如何在按钮按钮事件之外的Silverlight中获取鼠标按钮状态? [英] How to get the mouse button state in Silverlight outside of button press events?

查看:148
本文介绍了如何在按钮按钮事件之外的Silverlight中获取鼠标按钮状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况

当我的Silverlight应用程序中按下鼠标左键并执行某些操作时,我按下鼠标,鼠标移动。当左按钮被释放时,我关闭告诉它做的东西的标志,然后鼠标移动处理程序不再这样做。

I handle when the left mouse button is pressed in my Silverlight app and do some things while the mouse is held down and the mouse moves. When the left button is released, I turn off the flag that's telling it to do the stuff and the mouse movement handler then no longer does the stuff.

问题是:如果用户在控制区域,按下左按钮并移出控制区域,然后释放按钮和重新输入,MouseLeftButtonUp事件永远不会触发,并且处理将持续到用户单击鼠标。

The problem is: if the user is in the control area, pushes the left button down and moves out of the control area, then releases the button and reenters, the MouseLeftButtonUp event never fires and the processing continues until the user clicks the mouse.

我的临时修复是在MouseLeave上关闭鼠标标志,但这并不是我要做的。我想检查鼠标在MouseEnter事件中的左按钮状态,但我不知道如何做到这一点。

My temporary fix was to turn the mouse flag off on MouseLeave but that's not really what I'm going for. I'd like to check to see the mouse's left button state in the MouseEnter event, but I don't know of a way to do that.

有谁知道一种我可以访问Silverlight 3中的新闻事件之外的鼠标按钮状态的方法?谢谢,

Does anyone know of a way I can access the mouse button state outside of the press events in Silverlight 3? Thanks,

更新

经过深入研究,它看起来不像这是可能的Silverlight 2(可能是3.)我发现此链接。如果有人知道解决方法,请让我知道。

After thorough research, it doesn't look like this is possible in Silverlight 2 (and probably 3.) I found this link. If anyone knows of a workaround, please let me know.

推荐答案

您需要做的事情可以通过UIElement.CaptureMouse方法:

What you need to do can be accomplished with the UIElement.CaptureMouse method:

http://msdn.microsoft.com/en-us/library/system.windows.uielement.capturemouse%28VS.95%29.aspx

当UIElement捕获鼠标时,即使鼠标离开Silverlight控件,它也将继续接收鼠标事件。

When a UIElement has captured the mouse, it will continue to receive mouse events even if the mouse leaves the Silverlight control.

这篇关于如何在按钮按钮事件之外的Silverlight中获取鼠标按钮状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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