Reusing multiple resources with styles
So far, we have explored simple resources, which are made by a single XAML element. However, XAML supports also more complex types of resources, such as styles. If you are familiar with web development, XAML styles and CSS styles are similar, since they serve the same purpose – group together a set of resources so that you can apply all of them just by referencing the style.
This is an example of what a style looks like:
<Style x:Key="HeaderText" TargetType="TextBlock"> <Setter Property="Foreground" Value="Red" /> <Setter Property="FontSize" Value="24" /> </Style>
As with a single resource, a style is identified by a name assigned to the x:Key
property. However, we can also see a couple of important differences:
- We must specify a property called
TargetType
, which specifies the control type...