Tag Archives: Custom Markup Extensions

Silverlight 5 – Custom Markup Extensions

20 Apr

A Markup Extension is a class that decides at runtime how to set a property’s value. Markup extensions allow code to be run at XAML parse time for both properties and event handlers.

In Silverlight 4 we got some different Markup Extensions:

  • Binding
    Text=”{Binding Path=FirstName, Mode=TwoWay}”
  • StaticResource
    Foreground=”{StaticResource BlueSolidColor}”
  • TemplateBinding
    VerticalAlignment=”{TemplateBinding VerticalContentAlignment}”
  • NullExtension
  • RelativeSource
    DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"

With Silverlight 5 we get Custom Markup Extensions allowing us to write more specific and complex Markup Extensions.

Jeff Prosise’s have written a good sample here and Jeremy Likness have written about getting creating a custom markup extension that uses MEF to satisfy imports on object instances declared in XAML here.

by xamlgeek