#92 – Markup Extensions
October 12, 2010 2 Comments
When property values are specified in XAML, the property can get its value in one of three different ways:
- Property assigned a literal string value
- Property assigned a value by a type converter, converted from a literal string
- Property assigned based on a markup extension
A markup extension is special syntax that dictates where a property should get its value. Markup extensions are specified using braces–{, }.
<!-- Background property set using type converter -->
<Button Background="Red" Content="Dum" Height="23" Width="75" />
<!-- Background property set using the StaticResource markup extension -->
<Button Background="{StaticResource blueBrush}" Content="Dee" Height="23" Width="75" />
The most common markup extensions that you’ll encounter in WPF include:
- StaticResource - set property to object in resource dictionary
- DynamicResource - set property to resource, loading at run-time
- Binding - set property using data binding
- TemplateBinding – placeholder in a template, value comes from the object using the template
Pingback: Tweets that mention #92 – Markup Extensions « 2,000 Things You Should Know About WPF -- Topsy.com
Pingback: #158 – When to Create a Custom Dependency Property « 2,000 Things You Should Know About WPF