zoukankan      html  css  js  c++  java
  • 四、WPF 切换按钮背景图样式写法

     <!--1V按钮样式-->
        <Style TargetType="Button" x:Key="UButtonStyleOneVideo">
            <Setter Property="Height" Value="20" />
            <Setter Property="Width" Value="20" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Cursor" Value="Hand"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Image Name="img" Source="/images/1nor.png"  />
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True"  >
                                <Setter Property="Source" TargetName="img" Value="/images/1sel.png"></Setter>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True"  >
                                <Setter Property="Source" TargetName="img" Value="/images/1sel.png"></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
    
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    默认一张图片,通过触发器修改背景图

    如果新增文件,记得在App.xaml导入样式

    <Application x:Class="XX.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:local="clr-namespace:XX.Zhifa"
                 StartupUri="LoginWin.xaml">
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="Style/UButton.xaml"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
    
        </Application.Resources>
    </Application>

    在窗口中引入样式

     <Button Name="btnOneCamera"  VerticalAlignment="Center" Content="" Style="{DynamicResource UButtonStyleOneVideo}"Margin="0 0 0 0"  >
  • 相关阅读:
    Future接口和Callable接口以及FeatureTask详解
    puppet的使用:ERB模板介绍
    puppet的使用:依赖关系整理
    数字证书常见格式整理
    c3p0配置文件
    dockerfile简述
    Grape简介
    keytool和openssl生成的证书转换
    Grape教程-params
    耿丹CS16-2班助教总结
  • 原文地址:https://www.cnblogs.com/cvol/p/14415430.html
Copyright © 2011-2022 走看看