Has anyone ever created a custom markup extension in WPF or Silverlight? When would you ever want or need to do this? Any tips or sources on how to do it?
An example would be for Localization:
A simple and effective way to localize application resources is to write a custom MarkupExtension that provides a localized value. The extension takes a parameter that is a unique resource key... [and then] looks up the value from a generic resource provider.
Note: You can not write custom markup extensions in silverlight.
Yes it is handy and I have created one myself. I created a markup extension called EvalBinding that takes a set of bindings as children and a C# evaluation string. It evaluates the C# to process the values from the child bindings so that I do not need to create many simple TypeConverter classes.
For example I can do this...
<EvalBinding Eval="(this[0] > this[1] ? 'GT' : 'LTE')">
<Binding ElementName="element1" Path="Size"/>
<Binding ElementName="element2" Path="Size"/>
<EvalBinding>
Where this is a reference to the array of child binding results.
For resources on implementing a MarkupExtension...
MSDN
Josh Smith Blog Entry
Rob Relyea Blog Entry
Hooray!!
This is implemented in Silverlight 5!!
And furthermore, now it's a generic interface instead of a class!!
Check it out.
Read this for an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With