Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Problem with 'CommandBinding' and 'PreviewExecuted'

 
 
Old 03-03-2006   #1 (permalink)
Marcus


 
 

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


 
 

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


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
the problem with ndis.sys Blue Screen of Death problem solved? Vista General
Re: Windows Mail Attachement Problem and Adobe Player Problem with IE8 Vista mail
Generic McAfee Problem Message in Vista Problem Reports Vista performance & maintenance
fixed unable to delete email problem, now I have new problem Vista mail
Vista Upgrade Problem - Windows Explorer Loop problem Vista installation & setup


Vista Forums 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 Ltd

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