한 Page 내에서 Style이 같은 여러 개의 Button을 배치할 때...
<Page.Resources>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="3">
<Grid>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="Blue" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Cursor" Value="Hand" />
</Style>
</Page.Resources>
<Grid>
<Button Content="Button" Width="150" Height="45" FontFamily="Arial" Margin="186,198,464,207" />
<Button Content="Button2" Width="150" Height="45" FontFamily="Arial" Margin="341,198,309,207" />
<Button Content="Button3" Width="150" Height="45" FontFamily="Arial" Margin="496,198,154,207" />
</Grid>
또는 x:Key로 이름을 지정하여 특정 버튼만 Style을 적용할 수 있다.
<Page.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="3">
<Grid>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="Blue" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Cursor" Value="Hand" />
</Style>
</Page.Resources>
<Grid>
<Button Content="Button" Width="150" Height="45" FontFamily="Arial" Margin="186,198,464,207" />
<Button Style="{StaticResource ButtonStyle1}" Content="Button2" Width="150" Height="45" FontFamily="Arial" Margin="341,198,309,207" />
<Button Content="Button3" Width="150" Height="45" FontFamily="Arial" Margin="496,198,154,207" />
</Grid>