5

According to UIElement.AddHandler on MSDN, you can pass in a boolean for the handledEventsToo argument so you can still be notified of handled events. Is there a XAML equivalent to this?

Another way to do this is through the EventSetter class which also specifies that property, but it specifically says it shouldn't be used in XAML although they don't specify why, and I can't think of a good reason why not.

Only thing I can think of is it causing havoc when initializing the XAML which (most likely) wouldn't be the case if you did it in code as you'd most likely do so after InitializeComponent. However, that's a complete guess.

I'm actually thinking of subclassing my own version of the EventSetter class that will add that property, although I haven't given it much thought yet, or even know if that's possible, although I don't see why it wouldn't be.

Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286

1 Answers1

0

I was looking for the same thing but unfortunately, as per the latest MSDN documentation:

Setting the InvokeHandledEventsToo characteristics of how an event's handlers will be invoked must always be performed in code, in keeping with the general principle that there is no way to specify InvokeHandledEventsToo when assigning defined event handlers for instances directly to named events in XAML attribute syntax. Although setting this value in XAML does not generate any compile-time errors, the resulting XAML will produce a run-time exception when the style is used.

I think the purpose of handledEventsToo is to give more flexibility to custom controls where code-behind isn't a problem, as opposed to when you are coding with the "normal" MVVM pattern.

Mike Marynowski
  • 3,156
  • 22
  • 32