I am trying to get routed events that work with child controls that will manually trigger these events, and they will bubble and be processed at the main grid level. I basically want to do something like this:
<Grid Name="Root" WpfApplication5:SpecialEvent.Tap="Catcher_Tap"> <Grid.RowDefinitions> <RowDefinition Height="40" /> <RowDefinition Height="40" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <WpfApplication5:UserControl2 Grid.Row="0" x:Name="Catcher" /> <WpfApplication5:UserControl1 Grid.Row="1" /> <Frame Grid.Row="2" Source="Page1.xaml" /> </Grid>
But when I run my example, I get a null reference in the view structure, the application is never initialized, it fails when trying to load / initialize XAML (InitializeComponent ()). Here is a small file containing the event:
public class SpecialEvent { public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent( "Tap", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(UserControl1));
I basically want to copy the behavior of ButtonBase.Click allowing parents to subscribe to any click () buttons for their children. But it doesn't seem to work for anything other than ButtonBase.Click (). That is, when I turn off my custom WpfApplication5:SpecialEvent.Tap="Catcher_Tap" before ButtonBase.Click="Catcher_Tap" , it works. Any ideas why? What makes ButtonBase what I am not doing?
source share