How to do attached events properly #8997
Unanswered
mwpowellhtx
asked this question in
Q&A
Replies: 1 comment 4 replies
-
If I am reading your code right, how would WPF know which event to raise? You need to tell it, i.e. You can always see how WPF itself raises events. The first search result that comes up is: |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm not sure this is quite the right place to ask, but I am having difficulty making Attached (Routed) Events work properly.
Just from a XAML design perspective, I am fairly certain that the
class
scaffold and declaration and supporting Add and Remove handler code is correctly presented, because designer knows when the Add or Remove code is not there and complains.However, at runtime, trying to raise said event, it is not working. Deep in the WPF runtime, RoutedEvent is discovered as being
null
, which I'm sure cannot be correct, or I am missing something, there needs to be something else, unbeknownst to me, I need to do enabling the feature.If I just following the learn guidance, it seems like every other detail is rather verbose on the subject of declaration and connecting the dots with XAML design, but is strangely silent on the subject of actually raising the event. Even to the point where a paragraph is devoted to "boilerplate" internal events, do not need to raise those; yes, I know that, and would expect nothing less than that, the internals should be raising its own events. This is just plain irrelevant to the topic at hand.
Okay, so my event and handler delegate delcared as follows:
The
BubbleManager
class members. The class itself does not need to bestatic
, does it?And methods supporting raising the event:
The
MainWindow.xaml
:And supporting code behind:
There is nothing outrageously fantastic about any of that, it does build, and run, but the runtime falls over during
EventRoute.cs
line 46 throwing theArgumentNullException
:Which taking the preceding code at face value, prima facie, there is no reason why
routedEvent
should benull
here, correct? Unless there is some other thing we need to be doing in order to facilitate attached routed events being functional.Don't know if this is an actual WPF bug, or we're just being dumb or ignorate of some other aspect. Any insight would be helpful.
Beta Was this translation helpful? Give feedback.
All reactions