XAML markup extensions
Even though we can initialize class instances using XAML elements and set class members using XAML attributes, we can only set them as predefined constants in a XAML document.
To enhance the power and flexibility of XAML by allowing element attributes to be set from a variety of sources, we can use XAML markup extensions. With XAML markup extensions, we can set an attribute to values defined somewhere else, or a result processed by code at runtime.
XAML markup extensions can be specified in curly braces, as shown here:
<Button Margin="0,10,0,0" Text="Learn more"
Command="{Binding OpenWebCommand}"
BackgroundColor="{DynamicResource PrimaryColor}"
TextColor="White" />
In the preceding code, both the BackgroundColor
and Command
attributes have been set to markup extensions. BackgroundColor
has been set to DynamicResource
and Command
has been set to the OpenWebCommand...