WPF中鼠标触发器

button按钮属性绑定与触发事件。。话不多说上代码:

<Window x:Class="wpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <!--用了Key这个唯一的标志符-->
        <Style TargetType="Button" x:Key="btn">
            <!--字体的前景色-->
            <Setter Property="Foreground" Value="Red" />
            <!--字体的样式-->
            <Setter Property="FontFamily" Value="宋体"/>
            <Setter Property="FontSize" Value="30"/>
            <Setter Property="Width" Value="150"/>
            <Setter Property="Height" Value="50"/>
            <Setter Property="Content" Value="登陆"/>
            <Style.Triggers>
                <!--鼠标移入移出事件-->
                <Trigger  Property="IsMouseOver" Value="True">
                    <!--字体的前景色-->
                    <Setter Property="Background" Value="Yellow"/>
                    <Setter Property="Foreground" Value="White"/>
                    <!--字体大小-->
                    <Setter Property="FontSize" Value="15" />
                    <!--字体的样式-->
                    <Setter Property="FontFamily" Value="华文彩云" />
                </Trigger>
                <!--鼠标点击释放事件-->
                <Trigger  Property="IsPressed" Value="true">
                    <!--字体的前景色-->
                    <Setter Property="Foreground" Value="Cyan"/>
                    <!--字体大小-->
                    <Setter Property="FontSize" Value="15" />
                    <!--字体的样式-->
                    <Setter Property="FontFamily" Value="楷体" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Canvas>
        <Button  Style="{StaticResource btn}"></Button>
    </Canvas>
</Window>

效果如下:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值