码迷,mamicode.com
首页 > Windows程序 > 详细

WPF重写Button样式

时间:2018-01-18 14:58:35      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:content   col   class   window   vertica   horizon   target   res   sources   

首先指定OverridesDefaultStyle属性为True;

然后添加样式;

重写ControlTemplate;

 

<Window.Resources>
    <Style x:Key="UserButtonStyle" TargetType="Button">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Padding" Value="5 3" />
        <Setter Property="Background" Value="LightBlue" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Name="border" BorderThickness="0" BorderBrush="Black" Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Opacity" Value="0.8" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

 

WPF重写Button样式

标签:content   col   class   window   vertica   horizon   target   res   sources   

原文地址:https://www.cnblogs.com/bincoding/p/8310022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!