tags:

views:

103

answers:

1

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.

Any ideas?

A: 

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

http://tomlev2.wordpress.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

Thomas Levesque
Thanks Thomas, ingenious solution. BTW: I have managed to overcome the problem by creating an "ownership tracking" capability for my custom classes so that each instance is "aware" of who its "parent", in the XAML sense, is.
Raoul