开发者

Nested triggers in WPF

I'm designing an application that uses a considerable amount of nested controls. Without going开发者_开发百科 into too much (unnecessary) detail, the basic idea is that I have a ListView, where each ListItem may contain one or more ListViews, and this may repeat infinitely (ListView inside ListView).

I have set up a DragEnter/DragLeave trigger on each ListView, so that when the cursor enters the region, the background changes. The problem is that due to the nesting, the trigger fires on every single ListView in the hierarchy, which is not what I want - I would like only the ListView directly under the cursor to animate. Is there a simple way to prevent trigger propagation on nested controls?


You would need to prevent those events from bubbling up to the outer ListView, thus preventing the triggers from firing.

You may need to use a custom class that derives from ListView (e.g. MyListView) and override OnDragEnter/OnDragLeave and set e.Handled to true.

You may also be able to use a class handler for the ListView type, where again you'd set e.Handled to true. This may occur before the EventTrigger though, which would effectively prevent your trigger from firing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜