Prev | Current Page 126 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

In other
words, when the XAML parser encounters the previous statement, it creates an instance of
the StaticExtension class (passing in the string ???SystemColors.ActiveCaptionBrush??? as an
argument to the constructor) and then calls ProvideValue() to get the object returned by the
SystemColors.ActiveCaption.Brush shared property. The Foreground property of the
cmdAnswer button is then set with the retrieved object.
The end result of this piece of XAML is the same as if you??™d written this:
cmdAnswer.Foreground = SystemColors.ActiveCaptionBrush
Because markup extensions map to classes, they can also be used as nested properties, as
you learned in the previous section. For example, you can use the StaticExtension with the
Button.Foreground property like this:

Depending on the complexity of the markup extension and the number of properties you
want to set, this syntax is sometimes simpler.
Like most markup extensions, the StaticExtension needs to be evaluated at runtime
because only then can you determine the current system colors. Some markup extensions can
be evaluated at compile time. These include the NullExtension (which represents a Nothing
value) and the TypeExtension (which constructs an object that represents a .


Pages:
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138