<Page x:Class="ButtonWidthTemplate.Page2"
xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page2">
<Page.Resources>
<ControlTemplate x:Key="btnCustom" TargetType="{x:Type Button}">
<Border Name="border" BorderThickness="3" BorderBrush="Red"
Background="{TemplateBinding Foreground}">
<TextBlock Name="txtblk"
FontStyle="Italic"
Text="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}"
Foreground="{TemplateBinding Background}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border"
Property="CornerRadius" Value="12" />
<Setter TargetName="txtblk"
Property="FontWeight" Value="Bold" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="border"
Property="Background"
Value="{Binding Path=Background}"/>
<Setter TargetName="txtblk"
Property="Foreground"
Value="{Binding Path=Foreground}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Page.Resources>
<StackPanel>
<Button Template="{StaticResource btnCustom}"
HorizontalAlignment="Center" Margin="24"
FontSize="24" Padding="10">
Button with Custom Template
</Button>
<Button HorizontalAlignment="Center" Margin="24"
FontSize="24" Padding="10">
Normal Button
</Button>
<Button Template="{StaticResource btnCustom}"
HorizontalAlignment="Center" Margin="24"
FontSize="24" Padding="10">
Another Button with Custom Template
</Button>
</StackPanel>
</Page>
- Stackpanel의 3개의 Button 중에서 첫번째, 두번째의 Template 프로퍼티가 설정되어 있다.
- 이 템플릿은 전경색과 배경색을 바꾸게 된다.