zoukankan      html  css  js  c++  java
  • WPF圆角按钮与触发颜色变化

    <Button x:Name="button1" Content="按钮1" Margin="10,10,0,0" Cursor="Pen">
                <Button.Template>
                    <ControlTemplate>
                        <Border CornerRadius="15,15,15,15">
                            <Border.Background>
                                <SolidColorBrush x:Name="color2"></SolidColorBrush>
                            </Border.Background>
                            <Border.Triggers>
                                <EventTrigger RoutedEvent="Border.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="color2" Storyboard.TargetProperty="(SolidColorBrush.Color)" From="AliceBlue" To="AntiqueWhite" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever"></ColorAnimation>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Border.Triggers>
                        </Border>
                    </ControlTemplate>
                </Button.Template>
            </Button>
            <Button x:Name="button2" Content="按钮2" Margin="106,10,0,0" Opacity="0.5" BorderThickness="3" IsDefault="True" Click="button2_Click" Cursor="Wait" ToolTip="点击啊" HorizontalAlignment="Left"/>
            <Button x:Name="button3" Content="开始分析" Margin="10,77,0,0" Click="button3_Click">
                <Button.Template>
                    <ControlTemplate>
                        <Border BorderThickness="1" CornerRadius="16,16,16,16" >
                            <Border.Background>
                                <SolidColorBrush x:Name="ColorQ"/>
                            </Border.Background>
                            <Border.Triggers>
                                <EventTrigger RoutedEvent="Button.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="ColorQ"
                                                Storyboard.TargetProperty="(SolidColorBrush.Color)"
                                                From="Red" To="Green" Duration="0:0:5"
                                                AutoReverse="True" RepeatBehavior="Forever"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Border.Triggers>
                        </Border>
                    </ControlTemplate>
                </Button.Template>
            </Button>

     加上字体也变化:

            <Button x:Name="button1" Margin="10,10,0,0" Cursor="Pen" ToolTip="点击按钮" Click="button1_Click" Background="White">
                <Button.Template>
                    <ControlTemplate>
                        <Border CornerRadius="15,15,15,15">
                            <Label Content="点击分析" FontFamily="微软雅黑" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="12">
                                <Label.Foreground>
                                    <SolidColorBrush x:Name="FontColor"></SolidColorBrush>
                                </Label.Foreground>
                                <Label.Triggers>
                                    <EventTrigger RoutedEvent="Border.Loaded">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <ColorAnimation Storyboard.TargetName="FontColor" Storyboard.TargetProperty="(SolidColorBrush.Color)" From="#000000" To="#ffffff" Duration="0:0:10" AutoReverse="True" RepeatBehavior="Forever"></ColorAnimation>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
                                </Label.Triggers>
                            </Label>
                            <Border.Background>
                                <SolidColorBrush x:Name="color2"></SolidColorBrush>
                            </Border.Background>
                            <Border.Triggers>
                                <EventTrigger RoutedEvent="Border.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="color2" Storyboard.TargetProperty="(SolidColorBrush.Color)" From="Red" To="purple" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever"></ColorAnimation>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Border.Triggers>
                        </Border>
                    </ControlTemplate>
                </Button.Template>
            </Button>

     看效果:

  • 相关阅读:
    关于C51的中断函数要注意的几个问题
    WORD文档中插入页码的问题
    【转载】vim复制时的缩进
    【转载】在Linux下,一个文件也有三种时间,分别是:访问时间、修改时间、状态改动时间
    【转载】LINUX上MYSQL优化三板斧
    【转载】小结一下linux 2.6内核的四种IO调度算法
    【转载】linux挂载mount参数优化
    【转载】ipcs与Linux共享内存
    【转载】Linux下的IO监控与分析
    【转载】netstat--查看服务器[有效]连接数--统计端口并发数--access.log分析
  • 原文地址:https://www.cnblogs.com/SeNaiTes/p/9372908.html
Copyright © 2011-2022 走看看