• 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>

  • 相关阅读:
    Enumerable类
    富客户端
    Entity Framework
    使用C库函数写文件出错
    VC 打开目录 打开上次打开目录
    boost_1_45_0安装
    boost中bimap双向映射的初级学习
    VS2008安装失败
    最近使用文档, 最近保存文档, 最近运行记录
    IE升级为8.0后, VS2008出现Internet Explorer脚本错误对话框
  • 原文地址:https://www.cnblogs.com/Cindys/p/2505883.html
Copyright © 2020-2023  润新知