WPF滑鼠悬停 [英] WPF Mouse Over

查看:77
本文介绍了WPF滑鼠悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

触发鼠标悬停事件时链接方法的最佳方法是什么?

What is the best way to link a method when the mouse over event is fired?

一个例子.

当鼠标悬停在按钮上时.一种方法会触发,例如count.

when a mouse hovers over a button. A method fires such as count.

只要鼠标悬停在按钮上,计数就会不断增加.

So as long as the mouse is over the button, the count will keep on incrementing.

如何将鼠标悬停事件连接到方法?使用Xaml吗?!

How will i connect a mouse over event to a method? Using Xaml?!

有任何想法吗?!

推荐答案

一种方法是通过附加属性,尤其是如果您想重用此功能.

One way to do this is via an attached property, especially if you want to reuse this capability.

Expression Blend的Behavior<T>类使此过程变得简单.您将需要Blend SDK,但是您可以直接使用行为.这是显示示例的博客文章.

Expression Blend's Behavior<T> class makes this simple. You'll need the the Blend SDK, but then you can use behaviors directly. Here's a blog post showing an example.

这使您可以在XAML中分配附加行为.许多MVVM框架都有使用这种方法的实现,例如 Cinch中的LifetimeEvents .

This allows you to assign an attached behavior in XAML. Many MVVM frameworks have an implementation that uses this approach, such as the LifetimeEvents in Cinch.

这篇关于WPF滑鼠悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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