I am attempting to write a MarkupExtension
to support the process of instantiating custom types via XAML. My custom types are POCOs and not descendants of DependencyObject
. There seems to be no straightforward XAML mechanism for MarkupExtensions
to obtain references to objects in the graph that is being loaded. I note that the WPF machinery provides some of these capabilities but the relevant properties are all internal
.
我试图编写MarkupExtension来支持通过XAML实例化自定义类型的过程。我的自定义类型是POCO而不是DependencyObject的后代。 MarkupExtensions似乎没有直接的XAML机制来获取对正在加载的图中对象的引用。我注意到WPF机器提供了一些这些功能,但相关的属性都是内部的。
Any ideas?
1 个解决方案
#1
I wrote a class that I use to bind to ViewModel commands, and it contains some code to retrieve the root of the XAML. It uses reflection on private WPF members, so it's not exactly clean, but it works... You can find it here
我编写了一个用于绑定ViewModel命令的类,它包含一些代码来检索XAML的根。它使用私有WPF成员的反射,所以它不是很干净,但它的工作原理......你可以在这里找到它
http://www.thomaslevesque.com/2009/03/17/wpf-using-inputbindings-with-the-mvvm-pattern/
BTW, it doesn't work with WPF 4 because the private implementation has changed... If you're interested I can post an updated version that takes these changes into account
顺便说一句,它不适用于WPF 4,因为私有实现已经改变...如果您感兴趣我可以发布一个更新版本,将这些更改考虑在内
#1
I wrote a class that I use to bind to ViewModel commands, and it contains some code to retrieve the root of the XAML. It uses reflection on private WPF members, so it's not exactly clean, but it works... You can find it here
我编写了一个用于绑定ViewModel命令的类,它包含一些代码来检索XAML的根。它使用私有WPF成员的反射,所以它不是很干净,但它的工作原理......你可以在这里找到它
http://www.thomaslevesque.com/2009/03/17/wpf-using-inputbindings-with-the-mvvm-pattern/
BTW, it doesn't work with WPF 4 because the private implementation has changed... If you're interested I can post an updated version that takes these changes into account
顺便说一句,它不适用于WPF 4,因为私有实现已经改变...如果您感兴趣我可以发布一个更新版本,将这些更改考虑在内