zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    Failed to create the Java Virtual Machine
    图文解析进程与线程区别
    HTTP协议详解
    打开某网站无法访问出现空白页可能的原因
    子网划分举例
    上传验证绕过全解析
    Linux命令之远程登录与执行远程主机命令
    information_schema Introduction
    python多进程之multiprocessing
    python多线程之Threading
  • 原文地址:https://www.cnblogs.com/Cindys/p/2505883.html
Copyright © 2011-2022 走看看