Styling your applications with resources
Resources are one of the most powerful features of XAML, since they simplify the adoption of a unified theme across a whole application. Thanks to resources, you can define a snippet of XAML and reuse it across multiple controls in an application.
For example, let's say that you want a series of TextBlock
controls to display text in red. Instead of setting the Foreground
property of each control to Red
, you can define a resource with this setting, as shown in the following example:
<StackPanel> <StackPanel.Resources> <SolidColorBrush x:Key="MyBrush" Color="Red" /> </StackPanel.Resources> </StackPanel>
Resources are defined by a special property called x:Key
. It's the name we're going to use to reference this resource on our XAML...