wpf Button 默认样式存档,方便手头没有 vs 时查阅.
1 <Style x:Key="FocusVisual"> 2 <Setter Property="Control.Template"> 3 <Setter.Value> 4 <ControlTemplate> 5 <Rectangle Margin="2" StrokeDashArray="1 2" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" SnapsToDevicePixels="true" StrokeThickness="1"/> 6 </ControlTemplate> 7 </Setter.Value> 8 </Setter> 9 </Style> 10 <SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/> 11 <SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/> 12 <SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/> 13 <SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/> 14 <SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/> 15 <SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/> 16 <SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/> 17 <SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/> 18 <SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/> 19 <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}"> 20 <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> 21 <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/> 22 <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/> 23 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 24 <Setter Property="BorderThickness" Value="1"/> 25 <Setter Property="HorizontalContentAlignment" Value="Center"/> 26 <Setter Property="VerticalContentAlignment" Value="Center"/> 27 <Setter Property="Padding" Value="1"/> 28 <Setter Property="Template"> 29 <Setter.Value> 30 <ControlTemplate TargetType="{x:Type Button}"> 31 <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true"> 32 <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 33 </Border> 34 <ControlTemplate.Triggers> 35 <Trigger Property="IsDefaulted" Value="true"> 36 <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> 37 </Trigger> 38 <Trigger Property="IsMouseOver" Value="true"> 39 <Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/> 40 <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/> 41 </Trigger> 42 <Trigger Property="IsPressed" Value="true"> 43 <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/> 44 <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/> 45 </Trigger> 46 <Trigger Property="IsEnabled" Value="false"> 47 <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/> 48 <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/> 49 <Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/> 50 </Trigger> 51 </ControlTemplate.Triggers> 52 </ControlTemplate> 53 </Setter.Value> 54 </Setter> 55 </Style>