Wednesday, June 29, 2011

Markup Extensions in XAML

You can specify a value to an attribute using curly braces ‘{}’ is called as Markup Extensions in XAML. The most commonly used markup extensions in WPF are Binding, StaticResource, DynamicResources, RelativeSource, TemplateBinding etc. These all markup extensions are default provided by WPF. If you want you can create your own Markup Extension you can achieve it by deriving MarkupExtension class. Nested Markup Extensions also possible in XAML.

<Style x:Key="MyStyle" TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Red" />

      <Button Content="Click Me!" Style="{StaticResource MyStyle}" />

In above example Style attribute of Button uses StaticResource Markup Extension.


  1. Is the custom markup extension and what we talking above are same. ??

    1. In this post no custom markup extensions used. You can create your own markup extension as per your requirement,

  2. I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.