SepehrM
SepehrM

Reputation: 1097

Why are there no Preview event handlers in UWP?

In WPF, for most UI events, we have PreviewX event as well. How come there is no such a thing in Universal Apps? Is the events system fundamentally different from that of WPF that there is no need for it?

Upvotes: 2

Views: 491

Answers (1)

vrwim
vrwim

Reputation: 14320

Found the answer, the system has changed from bubbling and tunneling. Now it works with Routed Events. More information can be found here. Here is the important excerpt:

Earlier we said that setting Handled to true prevents most handlers from being called. But the AddHandler method provides a technique where you can attach a handler that is always invoked for the route, even if some other handler earlier in the route has set Handled to true in the shared event data.

So instead of adding the event handler as usual, you'll need to call AddHandler to add your "Preview" handler.

Something to note: the documentation does not say that these special handlers are executed before the regular ones, so it is not exactly the same as the PreviewX method.

Upvotes: 2

Related Questions