如何onmoveover改变按钮颜色,OnMouseLeave在WPF中使用触发器或任何其他事件 [英] How to change the button color onmoveover,onmouseleave in wpf by using triggers or any other events

查看:636
本文介绍了如何onmoveover改变按钮颜色,OnMouseLeave在WPF中使用触发器或任何其他事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一些按钮的WPF应用程序。现在我想改变这些按钮的颜色的onmouseover,OnMouseLeave在,OnMouseEnter在使用触发器或任何其他事件。
任何建议PLZ
先谢谢了。

I have developed a WPF Application with some buttons. Now i want to change the color of those buttons onmouseover,onmouseleave,onmouseenter by using triggers or any other events. Any suggestion plz Thanks in advance.

推荐答案

在需要的情况下,你可以设置背景颜色像这样...

Inside the desired event, you can set the background color like this...

// Change the background color of button1 to Blue
button1.Background = Brushes.Blue;

您还可以设置这触发:

<!-- Button will change from Blue to Yellow on MouseOver -->
<Style TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Blue" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Yellow" />
        </Trigger>
    </Style.Triggers>
</Style>

有关更详细信息,请查看属性触发器的<节href=\"http://www.microsoft.com/belux/msdn/nl/community/columns/gillcleeren/wpf%5Fstylesandtriggers.mspx\">this文章

For even more details, check out the Property Triggers section of this article.

这篇关于如何onmoveover改变按钮颜色,OnMouseLeave在WPF中使用触发器或任何其他事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆