
Using Styles to Change the Appearance of Multiple Controls
To apply the same property settings over multiple controls of the same type, you can create and apply a style to the type. A style is basically a collection of property settings applied to multiple instances of the same type. Styles are typically defined in XAML. The targetType of the style determines what type of control it is applied to. Alternatively, you can assign a x:Key to the style and reference it by name when you declare a type. For more information about styles, see Style.
The following code example demonstrates how to declare a style as a resource, assign it a key, and apply it to a button control in XAML.
<Style TargetType="Button" x:Key="myButtonStyle">
<Setter Property="Background" Value="Purple" />
<Setter Property="Foreground" Value="#9900FF" />
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="100" />
<Setter Property="Margin" Value="5" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="FontSize" Value="14" />
</Style>
...
<Button x:Name="button3" Width="130" Content="Click Me Instead!" Style="{StaticResource myButtonStyle}"/>