![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest
Posts: n/a
| RoutedCommand doesn't route in UI tree Hi, I am learning RoutedCommand and CommandBinding in WPF. I wrote a small test program as following, I hope when I put focus in the textbox and invoke my custom command with "ALT-C" the execute event will be routed from the textbox to the root window, however the execute event stops at the textbox and does not route to the window. Can anyone tell me why? <Window x:Class="WindowsApplication3.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WindowsApplication3" Height="300" Width="300" Loaded="OnLoaded"> <StackPanel> <TextBox x:Name="txt1">Foo</TextBox> </StackPanel> </Window> namespace WindowsApplication3 { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public static RoutedCommand myCommand; public Window1() { InitializeComponent(); } private void OnLoaded(Object sender, RoutedEventArgs e) { myCommand = new RoutedUICommand("myCommand", "myCommand", typeof(Window1)); myCommand.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Alt)); CommandBinding cmdBindingWindow = new CommandBinding(myCommand); cmdBindingWindow.Executed += NewCommandHandlerWindow; this.CommandBindings.Add(cmdBindingWindow); CommandBinding cmdBindingTxt = new CommandBinding(myCommand); cmdBindingTxt.Executed += NewCommandHandlerTxt; txt1.CommandBindings.Add(cmdBindingTxt); } private void NewCommandHandlerWindow(Object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("NewCommandHandlerWindow"); } private void NewCommandHandlerTxt(Object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("NewCommandHandlerTxt"); } } } |
| | #2 (permalink) |
| Guest
Posts: n/a
| Re: RoutedCommand doesn't route in UI tree Because you have a command handler attached to the text box, we assume the command is handled, and don't route further. -Nick Kramer [MSFT] http://blogs.msdn.com/nickkramer This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm "Daniel" <Daniel@discussions.microsoft.com> wrote in message news:92671C94-DD95-456F-8E6D-5C8794145340@microsoft.com... > Hi, > > I am learning RoutedCommand and CommandBinding in WPF. > I wrote a small test program as following, I hope when I put focus in the > textbox and > invoke my custom command with "ALT-C" the execute event will be routed > from > the > textbox to the root window, however the execute event stops at the textbox > and does > not route to the window. > > Can anyone tell me why? > > <Window x:Class="WindowsApplication3.Window1" > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > Title="WindowsApplication3" Height="300" Width="300" > Loaded="OnLoaded"> > <StackPanel> > <TextBox x:Name="txt1">Foo</TextBox> > </StackPanel> > </Window> > > namespace WindowsApplication3 > { > /// <summary> > /// Interaction logic for Window1.xaml > /// </summary> > > public partial class Window1 : Window > { > public static RoutedCommand myCommand; > > public Window1() > { > InitializeComponent(); > } > > private void OnLoaded(Object sender, RoutedEventArgs e) > { > > myCommand = new RoutedUICommand("myCommand", "myCommand", > typeof(Window1)); > myCommand.InputGestures.Add(new KeyGesture(Key.C, > ModifierKeys.Alt)); > > CommandBinding cmdBindingWindow = new > CommandBinding(myCommand); > cmdBindingWindow.Executed += NewCommandHandlerWindow; > this.CommandBindings.Add(cmdBindingWindow); > > CommandBinding cmdBindingTxt = new CommandBinding(myCommand); > cmdBindingTxt.Executed += NewCommandHandlerTxt; > txt1.CommandBindings.Add(cmdBindingTxt); > } > > private void NewCommandHandlerWindow(Object sender, > ExecutedRoutedEventArgs e) > { > Debug.WriteLine("NewCommandHandlerWindow"); > } > > private void NewCommandHandlerTxt(Object sender, > ExecutedRoutedEventArgs e) > { > Debug.WriteLine("NewCommandHandlerTxt"); > } > } > } |
| | #3 (permalink) |
| Guest
Posts: n/a
| Re: RoutedCommand doesn't route in UI tree Nick Kramer wrote: > Because you have a command handler attached to the text box, we assume > the command is handled, and don't route further. Shouldn't there be a feature parallel to AddHandler's handledEventsToo for commands? Maybe handledCommandsToo? -Drew |
| | #4 (permalink) |
| Guest
Posts: n/a
| Re: RoutedCommand doesn't route in UI tree Thanks for the help. But still the problem is that : > Because you have a command handler attached to the text box, we assume the > command is handled, and don't route further. Even if I mark the execute event as NOT handled in the that handler, the event still not get routed, for example like following: private void NewCommandHandlerTxt(Object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("NewCommandHandlerTxt"); e.Handled = false; } |
| | #5 (permalink) |
| Guest
Posts: n/a
| Re: RoutedCommand doesn't route in UI tree What Nick meant is that as soon as a handler is added for a command, the framework will mark the orignal routed event as handled as raise another event, directly aimed at calling your handler... In fact, if you add a handler for a command, it is to execute the command... therefore, command has reached it`s target (no more routing, we don`t want more than one people to execute "copy" [example] at the same time)... |
| | #6 (permalink) |
| Guest
Posts: n/a
| Re: RoutedCommand doesn't route in UI tree Could be. I've been a little reluctant to go there -- there's no xaml version of handledEventsToo so it felt a little weird having a xaml handledCommandsToo. And I don't want to bloat commanding too much, it's meant to be a convenience wrapper around input rather than the end all be all solution. But, I wouldn't be surprised if we do it at some point. -Nick Kramer [MSFT] http://blogs.msdn.com/nickkramer This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm "Drew Marsh" <drub0y@hotmail.no.spamming.com> wrote in message news:f01844f1f2c008c83b847f474efa@msnews.microsoft.com... > Nick Kramer wrote: > >> Because you have a command handler attached to the text box, we assume >> the command is handled, and don't route further. > > Shouldn't there be a feature parallel to AddHandler's handledEventsToo for > commands? Maybe handledCommandsToo? > > -Drew > > |
| | #7 (permalink) |
| Guest
Posts: n/a
| Re: RoutedCommand doesn't route in UI tree Ok, I've got it. Thanks a lot. "Marcus" wrote: > What Nick meant is that as soon as a handler is added for a command, > the framework will mark the orignal routed event as handled as raise > another event, directly aimed at calling your handler... > > In fact, if you add a handler for a command, it is to execute the > command... therefore, command has reached it`s target (no more routing, > we don`t want more than one people to execute "copy" [example] at the > same time)... > > |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Route Tables ?? | Howard Huntley | Vista General | 0 | 1 Week Ago 12:58 PM |
| Add Route | rfalken | Vista General | 1 | 05-28-2008 03:43 AM |
| Installation Route 66? | Huib | Vista General | 1 | 04-07-2007 03:11 PM |
| Help: Route Add Failed? | Nick | Vista General | 2 | 03-11-2007 07:45 PM |
| Route add doesn't work | Luca | Vista networking & sharing | 2 | 06-15-2006 08:58 AM |