WPF和工具提示中的MouseEvent [英] MouseEvents in WPF and ToolTips
问题描述
您好,我有一个从Canvas派生的自定义控件,在此画布中,我绘制了一堆线条和椭圆.我想要的是当我将鼠标悬停在视觉效果上时弹出的工具提示.现在,我可以获得单个视觉效果的点击事件,我遇到的问题是我只想在mouseOver(mouseEnter)事件上显示工具提示.但是,在画布上添加mouseenter事件意味着当鼠标进入画布而不是每个单独的可视元素时触发该事件.很好,我尝试使用mouseMove事件,该事件在逻辑上以某种方式进入那里,但工具提示未显示,我猜测工具提示延迟过长,并且鼠标移动事件使它失效太快了.
无论如何,如何在画布上的单个视觉对象上获取mouseEnter事件?或解决我的mouseMove事件问题.
不确定这是否是最好的方法.
在此先感谢您的帮助.
Hi
I have a custom control that derives from Canvas, in this canvas I draw a bunch of lines and ellipses. What I want is a tooltip to pop up when i mouse over the visuals. Now I can get hit events for the individual visuals, the problem I'm having is I only want to show the tooltip on the mouseOver (mouseEnter) events. However adding a mouseenter event to the canvas means that it gets triggered when the mouse enters the canvas and not each individual visual element. Fine I tried using the mouseMove event, which works in the way that logically it goes in there however the tooltip does not show up, I'm guessing that the tooltip delay is too long and the mouse move events are invalidating it too quickly.
Anyway any idea of how to get mouseEnter events on the individual visuals in the canvas? or a work around to my mouseMove event problem.
Not sure if this is the best approach for this.
Thanks for any help in advance.
推荐答案
您将哪些类型的元素放入Canvas中,如果它们是FrameworkElements,则可以直接设置其ToolTip属性,如果它们是Visuals,则可以连接到Canvas.MouseEnter事件,并调用VisualTreeHelper.HitTest()方法来测试鼠标所输入的视觉效果,如果存在视觉效果,则延迟几秒钟以显示工具提示.
希望这会有所帮助
这篇关于WPF和工具提示中的MouseEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!