Wpf Button 样式

 

上图片:

默认                  鼠标悬浮        鼠标按下

 

 

 

 

<Window.Resources>
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#F3F3F3" Offset="0"/>
<GradientStop Color="#EBEBEB" Offset="0.5"/>
<GradientStop Color="#DDDDDD" Offset="0.5"/>
<GradientStop Color="#CDCDCD" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Name="border" BorderThickness="1" BorderBrush="{TemplateBinding Background}" Background="{TemplateBinding Background}" CornerRadius="20">
<Label Name="label" FontSize="15" Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"></Label>
</Border>
<!-- <Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RenderDefaulted="{TemplateBinding IsDefaulted}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Themes:ButtonChrome>-->
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="border" Value="Green"></Setter>
<Setter Property="BorderBrush" TargetName="border" Value="Green"></Setter>
<Setter TargetName="label" Property="FontSize" Value="16"></Setter>
<Setter TargetName="label" Property="Foreground" Value="yellow"></Setter>

</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="border" Value="Yellow"></Setter>
<Setter Property="BorderBrush" TargetName="border" Value="Yellow"></Setter>
<Setter TargetName="label" Property="FontSize" Value="17"></Setter>
<Setter TargetName="label" Property="Foreground" Value="Green"></Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Button Width="100" Height="40" Content="点击" Background="Gray" Style="{DynamicResource ButtonStyle1}" Click="Button_Click"/>
</Grid>

</Window>

 

 http://www.cnblogs.com/pu-tao-zi/p/8873082.html 

posted @ 2018-04-18 11:26  葡萄老祖  阅读(683)  评论(1编辑  收藏  举报