tags:

views:

686

answers:

2

XAML allows you to specify an attribute value using a string that contains curly braces. Here is an example that creates a Binding instance and assigns it to the Text property of the TextBox element.

<TextBox Text="{Binding ElementName=Foo, Path=Bar}"/>

I want to extend XAML so that the developer could enter this as valid...

<TextBox Text="{MyCustomObject Field1=Foo, Field2=Bar}"/>

This would create an instance of my class and set the Field1/Field2 properties as appropriate. Is this possible? If so how do you do it?

If this is possible I have a followup question. Can I take a string "{Binding ElementName=Foo, Path=Bar}" and ask the framework to process it and return the Binding instance it specified? This must be done somewhere already to make the above XAML work and so there must be a way to ask for the same thing to be processed.

+1  A: 

The Binding class is a Markup Extension. You can write your own by deriving from System.Windows.Markup.MarkupExtension.

ElementName and Path are simply properties on the Binding object.

As for the followup you can create a new Binding in code by instantiating the Binding object. I do not know of a way to process a string through.

Brownie