I have a RoutedCommand defined like so:
public static class Commands
{
/// <summary>
/// Represents the Foo feature of the program.
/// </summary>
public static readonly RoutedCommand Foo = new RoutedCommand("Foo", typeof(Window1));
}
I then have a user control with the command defined like so:
<UserControl.CommandBindings>
<CommandBinding Command="{x:Static local:Commands.Foo}" Executed="CommandBinding_Executed"/>
</UserControl.CommandBindings>
<UserControl.InputBindings>
<KeyBinding Command="{x:Static local:Commands.Foo}" Modifiers="Control" Key="Space"></KeyBinding>
</UserControl.InputBindings>
and handled in code like so! (against my usercontrol class)
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Executed from sub");
}
My custom user control is defined in my main window:
<local:UserControl1 x:Name="myC" Grid.Row="1" DataContext="{Binding ChildName}"></local:UserControl1>
and my main window also has it's own way of dealing with the Foo routed command:
CommandBindings.Add(new CommandBinding(Commands.Foo, new ExecutedRoutedEventHandler((x, y) => {
MessageBox.Show("Something Happend from main window");
})));
InputBindings.Add(new InputBinding(Commands.Foo, new KeyGesture(Key.P, ModifierKeys.Alt)));
Now, if the the command was fired from my user control I would expect the event to bubble up to the window IF the Handled property of the ExecutedRoutedEventArgs is set to false, and it is:
But only the messagebox from the user control will show, I would expect the message box from the handled event on the window to show after!
Thank you