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>

  • 相关阅读:
    解决帝国CMS搜索页面模板不支持灵动标签和万能标签的方法
    Visual Studio Code 相关
    随机的背景图案
    将视频做为网页背景 超炫!
    gunicorn部署Flask服务
    查看mysql数据库及表编码格式
    查看修改mysql编码方式
    【ssm整合打印sql语句】
    【mybatis在控制台打印sql语句配置】
    【mybatis 的foreach的用法】
  • 原文地址:https://www.cnblogs.com/Cindys/p/2505883.html
Copyright © 2011-2022 走看看