• WPF按钮点击变色


     <Style x:Key="SwitchImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{x:Null}">
                    <Setter Property="Cursor" Value="Hand"/>
                    <Setter Property="Padding" Value="0"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Setter Property="BorderBrush" Value="{x:Null}"/>
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="Foreground" Value="Transparent"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
    BorderThickness="{TemplateBinding BorderThickness}"
     Padding="{TemplateBinding Padding}"/>

                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsFocused" Value="true">
                                        <!--IsPressed-->
                                        <Setter TargetName="Border" Property="Background" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>


    引用列子:


      <Button Canvas.Left="0" Canvas.Top="0" Height="45" x:Name="button1" Width="180"  Style="{StaticResource SwitchImageButtonStyle}" Command="{Binding RecentlyAddCmd}">
                <Button.Foreground>
                    <ImageBrush ImageSource="/MediaCenter;component/Images/Common_Shared/BottomBar/btns_recently_added_activated.png"></ImageBrush>
                </Button.Foreground>
                <Button.Background>
                    <ImageBrush ImageSource="/MediaCenter;component/Images/Common_Shared/BottomBar/btns_recently_added.png"/>
                </Button.Background>
            </Button>

  • 相关阅读:
    (基本知识)Redis 字符串(String)相关函数
    (基本知识)Redis 键相关命令函数
    (基本知识)Redis连接与安全
    centos7 php开发环境安装-Redis
    centos7 php开发环境安装--配置SSL(Apache为例)
    centos7 php开发环境安装-Git
    centos7 php开发环境安装-Nginx
    串口发送数据
    七大查找算法
    基于STM32原子战舰板内存管理源码详解
  • 原文地址:https://www.cnblogs.com/Cindys/p/2505883.html
Copyright © 2020-2023  润新知