#92 – Markup Extensions

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
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

3 Responses to #92 – Markup Extensions

  1. Pingback: Tweets that mention #92 – Markup Extensions « 2,000 Things You Should Know About WPF -- Topsy.com

  2. Pingback: #158 – When to Create a Custom Dependency Property « 2,000 Things You Should Know About WPF

  3. johnyao123 says:

    Thank you for put it so organized! Three ways to assign property value; and the common markup extensions and their functions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: