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

Problem with 'CommandBinding' and 'PreviewExecuted'

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-03-2006   #1 (permalink)
Marcus
Guest


 

Problem with 'CommandBinding' and 'PreviewExecuted'

Hi,

Has anybody encountered a problem such as this one:

In a Window, I declare a command binding to the 'copy' command... In
the command binding declaration, I map a function to the
'PreviewExecuted' routed event and to the 'Executed' routed event.

The XAML looks as follows:

<Window.CommandBindings>
<CommandBinding
Command="ApplicationCommands.Copy"
Executed="HandlerCopyExecute"
PreviewExecuted="HandlerCopyPreviewExecute"
/>
</Window.CommandBindings>

My problem is that whenever I map an Handler to the "PreviewExecuted"
event, then I won't receive the "Executed" event....

If I remove the handler to the "PreviewExecuted" event, then the
"Executed" event is called.

I did not find any indication in the SDK documentation indicating that
a particular action is required in the "PreviewExecuted" handler in
order to allow the "Executed" to occur!

I am using the February CTP, and I'm starting to wonder if this is a
bug in the WPF

Thanks


My System SpecsSystem Spec
Old 03-05-2006   #2 (permalink)
Sheva
Guest


 

Re: Problem with 'CommandBinding' and 'PreviewExecuted'

It seems that Microsoft deliberately prevents us from having PreviewExecuted
and Exectued events fired simultaneously, here is the evidence:
internal void OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (!e.Handled)
{
if (e.RoutedEvent == CommandManager.ExecutedEvent)
{
if ((this.Executed == null) ||
!this.CheckCanExecute(sender, e))
{
return;
}
this.Executed(sender, e);
e.Handled = true;
}
else if ((this.PreviewExecuted != null) &&
this.CheckCanExecute(sender, e))
{
this.PreviewExecuted(sender, e);
e.Handled = true;
}
}
}
This method is a part of implementation of CommandBinding class.Sheva

"Marcus" <larochem@gmail.com> wrote in message
news:1141392914.254252.14250@i39g2000cwa.googlegroups.com...
> Hi,
>
> Has anybody encountered a problem such as this one:
>
> In a Window, I declare a command binding to the 'copy' command... In
> the command binding declaration, I map a function to the
> 'PreviewExecuted' routed event and to the 'Executed' routed event.
>
> The XAML looks as follows:
>
> <Window.CommandBindings>
> <CommandBinding
> Command="ApplicationCommands.Copy"
> Executed="HandlerCopyExecute"
> PreviewExecuted="HandlerCopyPreviewExecute"
> />
> </Window.CommandBindings>
>
> My problem is that whenever I map an Handler to the "PreviewExecuted"
> event, then I won't receive the "Executed" event....
>
> If I remove the handler to the "PreviewExecuted" event, then the
> "Executed" event is called.
>
> I did not find any indication in the SDK documentation indicating that
> a particular action is required in the "PreviewExecuted" handler in
> order to allow the "Executed" to occur!
>
> I am using the February CTP, and I'm starting to wonder if this is a
> bug in the WPF
>
> Thanks
>



My System SpecsSystem Spec
Old 03-06-2006   #3 (permalink)
Marcus
Guest


 

Re: Problem with 'CommandBinding' and 'PreviewExecuted'

After this answer from Sheva, I took a deeper look at the code and
realized the following...

The "PreviewExecuted" in the CommandBinding is completelly useless...

>From what I see, the CommandBinding object only registers to the

"Executed" RoutedEvent of the Command... Meaning that the "tunneling"
effect expected from the "PreviewExecuted" would not occur, it is
simply the same thing as the the "Executed"...

Why would Microsoft put a "Preview" executed in the CommandBinding
then?

More than that, even if it can be "easilly" deduced, the events
originating from the "CommandBinding" are not routed at all, they are
plain old .NET events... I originally had some confusion about routing
of the command events because of it...

The code snippet from Sheva illustrate that behavior really well...

Thanks a lot...


Sheva wrote:
> It seems that Microsoft deliberately prevents us from having PreviewExecuted
> and Exectued events fired simultaneously, here is the evidence:
> internal void OnExecuted(object sender, ExecutedRoutedEventArgs e)
> {
> if (!e.Handled)
> {
> if (e.RoutedEvent == CommandManager.ExecutedEvent)
> {
> if ((this.Executed == null) ||
> !this.CheckCanExecute(sender, e))
> {
> return;
> }
> this.Executed(sender, e);
> e.Handled = true;
> }
> else if ((this.PreviewExecuted != null) &&
> this.CheckCanExecute(sender, e))
> {
> this.PreviewExecuted(sender, e);
> e.Handled = true;
> }
> }
> }
> This method is a part of implementation of CommandBinding class.Sheva
>
> "Marcus" <larochem@gmail.com> wrote in message
> news:1141392914.254252.14250@i39g2000cwa.googlegroups.com...
> > Hi,
> >
> > Has anybody encountered a problem such as this one:
> >
> > In a Window, I declare a command binding to the 'copy' command... In
> > the command binding declaration, I map a function to the
> > 'PreviewExecuted' routed event and to the 'Executed' routed event.
> >
> > The XAML looks as follows:
> >
> > <Window.CommandBindings>
> > <CommandBinding
> > Command="ApplicationCommands.Copy"
> > Executed="HandlerCopyExecute"
> > PreviewExecuted="HandlerCopyPreviewExecute"
> > />
> > </Window.CommandBindings>
> >
> > My problem is that whenever I map an Handler to the "PreviewExecuted"
> > event, then I won't receive the "Executed" event....
> >
> > If I remove the handler to the "PreviewExecuted" event, then the
> > "Executed" event is called.
> >
> > I did not find any indication in the SDK documentation indicating that
> > a particular action is required in the "PreviewExecuted" handler in
> > order to allow the "Executed" to occur!
> >
> > I am using the February CTP, and I'm starting to wonder if this is a
> > bug in the WPF
> >
> > Thanks
> >


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-select problem in Windows Explorer BIG PROBLEM!!!!!! Jim Hansen Vista General 3 12-16-2007 08:09 PM
Generic McAfee Problem Message in Vista Problem Reports cyberbuff53 Vista performance & maintenance 0 12-01-2007 07:55 AM
fixed unable to delete email problem, now I have new problem j2 Vista mail 19 03-29-2007 08:25 PM
audio problem with my sony vaio laptop and x64 problem =?Utf-8?B?YWxleA==?= Vista hardware & devices 1 07-14-2006 09:32 AM
Vista Upgrade Problem - Windows Explorer Loop problem Steve S Vista installation & setup 0 06-27-2006 10:15 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 50 51