Button 模板和样式

 1     <Style TargetType="{x:Type Button}">
 2         <Setter Property="FontFamily" Value="Microsoft YaHei"/>
 3         <Setter Property="FontSize" Value="12"/>
 4         <Setter Property="BorderThickness"  Value="1"/>
 5         <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
 6         <Setter Property="Background" Value="{DynamicResource ButtonBackground}"/>
 7         <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorder}"/>
 8         <Setter Property="BorderThickness" Value="1"/>
 9         <Setter Property="Foreground" Value="{DynamicResource ButtonText}"/>
10         <Setter Property="HorizontalContentAlignment" Value="Center"/>
11         <Setter Property="VerticalContentAlignment" Value="Center"/>
12         <Setter Property="Padding" Value="16,3,16,5"/>
13         <Setter Property="Template">
14             <Setter.Value>
15                 <ControlTemplate TargetType="{x:Type Button}">
16                     <Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
17                         <ContentPresenter x:Name="Presenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
18                     Border>
19                     <ControlTemplate.Triggers>
20                         <Trigger Property="IsEnabled" Value="False">
21                             <Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}"/>
22                         Trigger>
23                         <Trigger Property="IsMouseOver" Value="True">
24                             <Setter Property="Background" Value="{DynamicResource ButtonBackgroundHover}"/>
25                             <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderHover}"/>
26                             <Setter Property="Foreground" Value="{DynamicResource ButtonTextHover}"/>
27                         Trigger>
28                         <Trigger Property="IsPressed" Value="True">
29                             <Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}"/>
30                             <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderPressed}"/>
31                             <Setter Property="Foreground" Value="{DynamicResource ButtonTextPressed}"/>
32                         Trigger>
33                         <Trigger Property="IsFocused" Value="True">
34                             <Setter Property="BorderBrush" TargetName="Chrome" Value="{DynamicResource Accent}"/>
35                         Trigger>
36                     ControlTemplate.Triggers>
37                 ControlTemplate>
38             Setter.Value>
39         Setter>
40     Style>

 

其中

<第5行>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>

 

这个 Property 设置的是当有焦点时显示的样式,Value 设置为 x:Null 代表不会有任何改变,当然你也可以自己写一个。

 

应用

1 <Button Content="button" Height="23" Width="75"/>
2 <Button Content="Disabled" IsEnabled="False" Height="23" Width="75"/>

 

引用:

https://msdn.microsoft.com/zh-cn/library/ms753328(v=vs.110).aspx

转载于:https://www.cnblogs.com/SunsetAzure/p/6164984.html

你可能感兴趣的:(Button 模板和样式)