• WPF ControlTemplate


    ButtonStyle.xaml

    View Code
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <SolidColorBrush  x:Key="whiteSolidBrush" Color="White"/>
        <SolidColorBrush  x:Key="blackSolidBrush" Color="Black"/>
    
        <LinearGradientBrush  x:Key="blackToWhiteLGBrush">
            <GradientStop Offset="0" Color="Black"/>
            <GradientStop Offset="1" Color="White"/>
        </LinearGradientBrush>
    
        <RadialGradientBrush x:Key="blackToWhiteRGBrush">
            <GradientStop Offset="0" Color="Black"/>
            <GradientStop Offset="1" Color="White"/>
        </RadialGradientBrush>
    
        <ControlTemplate x:Key="buttonTemplate" TargetType="Button">
           <Grid>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState Name="Normal"/>
                        <VisualState Name="MouseOver"/>
                        <VisualState Name="Pressed">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="border"
                                                                Storyboard.TargetProperty="Background">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                            Value="{StaticResource whiteSolidBrush}"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentControl"
                                                                Storyboard.TargetProperty="Foreground">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0"                
                                                            Value="{StaticResource blackSolidBrush}"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState Name="Disabled">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="disabRectangle"
                                                 Storyboard.TargetProperty="Opacity"
                                                 To="0.6" Duration="0:0:0"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
               
               <Border Name="border"
                       BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}"
                       BorderThickness="{TemplateBinding BorderThickness}"
                       CornerRadius="5">
                   <ContentControl Name="contentControl"
                                   Content="{TemplateBinding Content}"
                                   ContentTemplate="{TemplateBinding ContentTemplate}"
                                   Margin="{TemplateBinding Padding}"
                                   HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                   VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
               </Border>
                <Rectangle Name="disabRectangle"
                           Fill="Gainsboro"
                           Opacity="0"/> 
            </Grid>
       </ControlTemplate>
        
        <Style x:Key="buttonStyle" TargetType="Button">
            <Setter Property="BorderBrush" Value="White"/>
            <Setter Property="BorderThickness" Value="5"/>
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="Template" Value="{StaticResource buttonTemplate}"/>
        </Style>
    </ResourceDictionary>

    使用

    <Button x:Name="bt" Content="123" Style="{StaticResource buttonStyle}" IsEnabled="False"/>
  • 相关阅读:
    『Delphi』字符串操作——返回子串出现的位置
    2007:远见、劲取、专注
    『转载』个人博客吸引风投关注成可盈利业务
    [和管子对话] 1 200745/对面向对象的你言我语
    『Delphi』File not found的解决办法
    Ruby学习1字符串
    聚集表(clustered table)data page中的数据行可以无序
    通过DBCC PAGE查看页信息验证聚集索引和非聚集索引节点信息
    查看SQL Server Resource Database以及修改系统表
    SQL Server的还原(2)——STOPAT
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/3075755.html
Copyright © 2020-2023  润新知