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"  >
  • 相关阅读:
    课表
    hz评测机的迷惑操作
    联赛模拟测试16
    第四阶段总结
    震惊!OI居然还考天体运动
    简单题 题解
    P2340 [USACO03FALL]Cow Exhibition G题解
    题目分享I 三代目
    题目分享H 三代目
    题目分享G 三代目
  • 原文地址:https://www.cnblogs.com/cvol/p/14415430.html
Copyright © 2011-2022 走看看