Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

RoutedCommand doesn't route in UI tree

Closed Thread
 
Thread Tools Display Modes
Old 05-01-2006   #1 (permalink)
Daniel
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");
}
}
}
 
Old 05-01-2006   #2 (permalink)
Nick Kramer [MSFT]
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");
> }
> }
> }



 
Old 05-01-2006   #3 (permalink)
Drew Marsh
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


 
Old 05-01-2006   #4 (permalink)
Daniel
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;
}
 
Old 05-02-2006   #5 (permalink)
Marcus
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)...

 
Old 05-02-2006   #6 (permalink)
Nick Kramer [MSFT]
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
>
>



 
Old 05-16-2006   #7 (permalink)
Daniel
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)...
>
>

 
 
Closed Thread

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








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49