Button 模板和样式

     <Style TargetType="{x:Type Button}">
<Setter Property="FontFamily" Value="Microsoft YaHei"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="{DynamicResource ButtonBackground}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource ButtonText}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="16,3,16,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<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}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundHover}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderHover}"/>
<Setter Property="Foreground" Value="{DynamicResource ButtonTextHover}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderPressed}"/>
<Setter Property="Foreground" Value="{DynamicResource ButtonTextPressed}"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" TargetName="Chrome" Value="{DynamicResource Accent}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

其中

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

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

应用

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

Button 模板和样式

引用:

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

上一篇:Checkbox 模板和样式


下一篇:如何用Web技术开发Windows Form应用