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>

  • 相关阅读:
    分析WordPress数据表之用户表(功能篇)
    Android.mk简介:
    win10 mars xlog编译
    sudo apt-get install libstdc++6
    WebRTC 入门教程(二)| WebRTC信令控制与STUN/TURN服务器搭建
    Mars Android 接入指南
    Mars Sample 使用说明
    RxJava2 方法总结
    mqtt client api: 阻塞API
    idea使用git进行项目管理
  • 原文地址:https://www.cnblogs.com/Cindys/p/2505883.html
Copyright © 2011-2022 走看看