开发者

Preventing WPF event tunneling

I would need to draw lots of WPF-paths. I have set them to children of canvas. Problems is that events are tunneled to path-objects.开发者_开发百科 That slows down the performance. I know overriding preview-method fix the problem, but do I really have to override all preview-methods..


I think you can catch the event in the Canvas and set e.Handled to true.


I found solution. I set path objects's IsHitTestVisible-property to false. Now they doesn't slow down the performance.


Not to resurrect old questions but, if there were e.g. buttons instead of paths, setting IsHitTestVisible to true would have not been ok since it effectively prevents Click and other events.

In my case I had a TabItem with a PreviewMouseMove event and a Button on that very TabItem with a Click event that didn't fire. The thing is that if you got a tunneling event (like PreviewMouseMove) on a parent control, it will "override" similar events on its child controls. A possible solution - the one that worked out for me - is picking up a different bubbling event, like MouseMove.

In short, bubbling events propagate to parent elements, while tunneling events propagate to child elements; there are also direct events that do not propagate at all.

More on the topic here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜