tags:

views:

68

answers:

2

For example I have the following binding markup

Text="{Binding Path=FirstName}"

pretty simply but it could be much more complex, I need to be able to parse this markup and get it into some objectified form such as an instance of the Binding class.

Something that could work in reverse, an instance of the binding class to spit out the markup would be great as well.

I know such a thing must exist in the framework but I dont know where/what class.

I have looked at XamlReader but was unable to get it working because in this case I am missing context as I am only working with bits of the project and not the whole.

+2  A: 

You can get the Binding object using GetBindingExpression, for example if you have:

<TextBlock Name="MyTextBlock" Text="{Binding Name}"/>

You can use:

BindingExpression expr = BindingExpression.GetBindingExpression(MyTextBlock, TextBlock.TextProperty);
Binding bindingObject = expr.ParentBinding;
Nir
A: 

To use XAMLReader you have to surround it with a valid root. then this shoudl work.

Hades32