Totty
Totty

Reputation: 916

How to force a control to not pass a click event up the tree? WPF C#

Is it possible to set up a Grid or other container control to be sort of an event dam? So that when any events, specifically a left click, that start within it are working their way up that they stop at that control and go no further?

Upvotes: 2

Views: 1002

Answers (2)

Arcturus
Arcturus

Reputation: 27065

PreviewMouseDown is your friend...

Add this event to your control, and set the Handled property on true...

All events tunnel first from root to leaves in the preview fase, then they are handled from leaves to root in the actual event case...

So PreviewMouseDown handles the Grid before the Button, while the MouseDown event handles the Button before the Grid...

hope this helps...

Upvotes: 7

Berkshire
Berkshire

Reputation: 700

You should be able to extend whatever control you want (assuming it is not sealed). In your extended class you can override the click event and swallow it (do not pass it to the base class).

Upvotes: 1

Related Questions