在上一个问题/答案中,我了解了 Windows Phone 中的数据绑定(bind)如何为 string
进行类型转换。至ImageSource
使用 TypeConverterAttribute
- 见 https://stackoverflow.com/a/16753488/373321
我现在正在查看 TypeConverterAttribute
的 WindowsStore 应用程序中的相同问题。 doesn't exist .
如果我使用 WinRT 数据绑定(bind),那么显然数据绑定(bind)层仍然可以进行正确的转换。 MSDN documentation说:
this behavior relies on underlying type conversion that processes the string as a URI, and calls the equivalent of the BitmapImage(Uri) constructor.
但是,我在任何地方都看不到任何关于它如何知道要进行什么转换的元数据。
我正在尝试构建自己的数据绑定(bind)实现——因此能够模仿 WinRT 的功能将非常有用。
是否有可查询的元数据提示告诉 Xaml 数据绑定(bind)应用什么转换?或者这是
string
至ImageSource
转换以某种方式烘焙到运行时,隐藏在 CLR 层中?如果它是隐藏的,是否有任何已知自动类型转换的列表,以便我可以将它们缓存在我的数据绑定(bind)实现中?
最佳答案
我通过 Twitter 与一位 WinRT 开发人员 (Tim Heuer) 讨论了这个问题
这次谈话的基本总结是:
TypeConverterAttribute
这样的东西。 关于data-binding - WindowsRT 数据绑定(bind)如何在没有 TypeConverterAttribute 的情况下进行类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17220538/