Chapter 2: XAML
Properties and Events in XAML
Markup Extensions
You may want to set a property value dynamically by binding it to a property in another control. Markup extensions can be used in nested tags or in XML attributes, which is more common. When they're used in attributes, they are always bracketed by curly braces {}.
<Button ... Foreground="{x:Static SystemColors.ActiveCaptionBrush}" >
it is equivalent to C# code in behind class:
cmdAnswer.Foreground = SystemColors.ActiveCaptionBrush;
When being used as nested properties, it becomes:
<Button ... >
<Button.Foreground>
<x:Static Member="SystemColors.ActiveCaptionBrush"></x:Static>
</Button.Foreground>
</Button>
Attached Properties
Attached properties always use a two-part name in this form: DefiningType.PropertyName, like:
<TextBox ... Grid.Row="0">
Attached properties aren't really properties at all. They're translated into method calls. ...so the parser calls Grid.SetRow(), which is:
Grid.SetRow(txtQuestion, 0);
The row number is actually stored in the object that it applies to—in this case, the TextBox object.
TextBox derives from the DependencyObject base class, the DependencyObject is designed to store a virtually unlimited collection of dependency properties.
In fact, the Grid.SetRow() method is a shortcut that's equivalent to calling the DependencyObject.SetValue() method, as shown here:
txtQuestion.SetValue(Grid.Row