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.

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

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

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

5 comments:

  1. A people without the knowledge of their past history, origin and culture is like a tree without roots. See the link below for more info.


    #origin
    www.matreyastudios.com

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

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

      Delete
  3. 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.


    edupdf.org

    ReplyDelete
  4. Now this is the kinda of stuff i like to read about. Thanks for brightening my day

    Jorcel
    www.imarksweb.org

    ReplyDelete