R – How to listen to a RoutedEvent from a class that doesn’t derive from FrameworkElement ? Can it be done routed-eventswpf The question says it all basically. I want in a class MyClass to listen to a routed event. Can it be done ? Best Solution Actually I wiredup the event the wrong way :| I had EventManager.RegisterClassHandler ( typeof ( MyClass )...... Instead of EventManager.RegisterClassHandler ( typeof ( TheClassThatOwnedTheEvent ) So .. my bad. Related SolutionsR – In WPF, is it possible to specify multiple routed events for a single event trigger Sorry... WPF's implementation of the EventTrigger only allows one routed event. Typically you would be firing a storyboard from a routed event. I would suggest the following compromise: <!--Define a storyboard as a resource--> <Storyboard x:Key="MyStoryboard1"> <!--Many properties and etc...--> </Storyboard> <Style.Triggers> <EventTrigger RoutedEvent="Button.MouseEnter"> <BeginStoryboard Storyboard="{StaticResource MyStoryboard1}"> <!--Other properties/name if necessary--> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="Button.MouseDown"> <BeginStoryboard Storyboard="{StaticResource MyStoryboard1}"> <!--Other properties/name if necessary--> </BeginStoryboard> </EventTrigger> </Style.Triggers> The concept is to reduce duplicate code by sharing resources. Hope this helps! R – WPF and routed event Implement a method to be called from the event handlers of the Button and StackPanel's. Sets the Handled property of the args to false. Or you can have a Boolean parameter in your GenericHandler method so that you can decide whether it should let the event bubble. void GenericHandler(object sender, RoutedEventArgs args) { // Check for the type of the args here and do your work. args.Handled = false; // this lets the event bubbled up. ... } Related QuestionC# – Metadata file ‘.dll’ could not be found
Best Solution
Actually I wiredup the event the wrong way :|
I had
Instead of
So .. my bad.