Want to set your XAML property value to an object?

Do you want to set your XAML property value to an object, the answer is Markup Extensions. Markup Extensions helps you set XAML property values to an object or may be dynamically at runtime.

For example, suppose you want to set the the Foreground property for a TextBlock control to the static property SystemColors.ActiveCaptionBrush. You can achieve this through the code behind through the following statement:

textBlock.Foreground = SystemColors.ActiveCaptionBrush;

Alternatively, you can do this through the XAML editor directly using the following statement:

< TextBlock x:Name="textBlock" Foreground="{x:Static SystemColors.ActiveCaptionBrush}" / >

Markup extensions is used through the syntax {MarkupExtensionClass Argument}. In this case, the
markup extension was a StaticExtension class, SystemColors.

MarkupExtension must be enclosed within braces { }


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: