Guest

How to rewrite WPF routed commands dispatching mechanism

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 1.91 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <Window x:Class="WpfApplication1.Window1"
  2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.     xmlns:local="clr-namespace:WpfApplication1">
  5.     <StackPanel>        
  6.         <TextBox x:Name="textBlock1">
  7.             <TextBox.CommandBindings>
  8.                 <CommandBinding Command="local:Window1.TestCommand" Executed="CommandBinding_Executed_1" />
  9.                 <CommandBinding Command="local:Window1.ForwardedTestCommand" Executed="CommandBinding_Executed_1" />
  10.             </TextBox.CommandBindings>
  11.         </TextBox>
  12.         <TextBox x:Name="textBlock2">
  13.             <TextBox.CommandBindings>
  14.                 <CommandBinding Command="local:Window1.TestCommand" Executed="CommandBinding_Executed_2" />
  15.             </TextBox.CommandBindings>
  16.             <TextBox.InputBindings>
  17.                 <KeyBinding Command="local:Window1.TestCommand" Gesture="Ctrl+G" />
  18.                 <KeyBinding Command="local:Window1.ForwardedTestCommand" Gesture="Ctrl+H" />
  19.             </TextBox.InputBindings>
  20.         </TextBox>
  21.     </StackPanel>
  22. </Window>
  23.        
  24. using System.Windows;
  25. using System.Windows.Input;
  26.  
  27. namespace WpfApplication1
  28. {
  29.     public partial class Window1 : Window
  30.     {
  31.         public static RoutedUICommand TestCommand = new RoutedUICommand("TestCommand", "TestCommand", typeof(Window1));
  32.         public static RoutedUICommand ForwardedTestCommand = new RoutedUICommand("ForwardedTestCommand", "ForwardedTestCommand", typeof(Window1));
  33.  
  34.         public Window1()
  35.         {
  36.             InitializeComponent();
  37.         }
  38.  
  39.         private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e)
  40.         {
  41.             MessageBox.Show("CommandBinding_Executed_1");
  42.         }
  43.  
  44.         private void CommandBinding_Executed_2(object sender, ExecutedRoutedEventArgs e)
  45.         {
  46.             MessageBox.Show("CommandBinding_Executed_2");
  47.         }
  48.     }
  49. }