It sure has been quiet of late, I agree.

 

I've never had to set CommandTarget on the ContextMenu; what you're
having to do is news to me.

 

Here's some sample code from a modal view in a recent project.  In the
constructor of the view, DataContext is set to this:

 

<wpf:ExtendedDataGrid.ContextMenu>

    <ContextMenu>

        <!--Include-->

        <MenuItem Command="{Binding CommandIncludeFacilities}">

            <MenuItem.Icon>

                <wpf:GreyToggleImage Margin="0,-1,0,0"
VerticalAlignment="Center" Source="{Binding Source={x:Static
constants:ImageConstants.ADD_BUTTON}}" Width="16" Height="16"
RenderOptions.BitmapScalingMode="NearestNeighbor"/>

            </MenuItem.Icon>

            <MenuItem.Header>

                <TextBlock Text="Include" VerticalAlignment="Center"
Margin="0,0,-8,0" />

            </MenuItem.Header>

        </MenuItem>

        

        <!-[snip]-->

 

    </ContextMenu>

</wpf:ExtendedDataGrid.ContextMenu>

 

I have an ICommand on the codebehind that is set to a concrete
DelegateCommand when the presenter is set by the DI system (this project
uses an MVP pattern).  It's a typical Command setup; nothing special to
see here.

 

If I wanted to pass control to the parent window, I would still bind it
to the ICommand on the view, and in my presenter either use the
messaging system to pass to the parent view's presenter, or get a
callback from the parent view's presenter into the modal view's
presenter to call.  Either way I'm palming off the handling of the
command to the parent by passing control up the line somehow.

 

Carl.

 

Carl Scarlett

Senior .NET/WPF Developer, UX Designer | Genesis

Enterprise Services | Bankwest

A: Level 3, Home Zone 3B, 300 Murray Street | Perth | Western Australia
| 6000

P: (08) 9369 5161

M: 0408 913 870

E: [email protected] <mailto:[email protected]> 

 

Description: cid:[email protected]

 

 

 

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Greg Keogh <[email protected]>
Sent: Thursday, 23 August 2012 5:38 PM
To: "'ozWPF'" <[email protected]>
Subject: ContextMenu command target

 

Folks (is this group alive?)

 

When putting context menu items on controls inside my app window I add
this:

 

CommandTarget="{Binding Path=PlacementTarget,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type
ContextMenu}}}"

 

Ages ago I found that this is necessary to allow the command to find the
binding target which is the parent app window. It was an early gotcha in
WPF.

 

Now I have a context menu in a modal dialog Window and the menu is
always disabled. It obviously can't find the app window as the command
target. Does anyone know of the correct syntax (if it exists) to allow a
command in a modal Window to be handled by the owner app window? I
fiddled around with variations of the code above but it does nothing.
Web searches produce nothing useful for me. I've wasted over an hour on
this already (as usual).

 

Thanks

Greg

 

 


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud
service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

_______________________________________________ 
ozwpf mailing list 
[email protected] 
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf 

________________________________________________________________________
_______ 

This email has been scanned by the Bankwest Email Security System. 
________________________________________________________________________
_______ 

_______________________________________________________________________________
Unencrypted electronic mail is not secure and may not be authentic.
If you have any doubts as to the contents please telephone to confirm.

This electronic transmission including any attachments is intended only
for those to whom it is addressed. It may contain copyright material or
information that is confidential, privileged or exempt from disclosure by law.
Any claim to privilege is not waived or lost by reason of mistaken transmission
of this information. If you are not the intended recipient you must not
distribute or copy this transmission and should please notify the sender.
Your costs for doing this will be reimbursed by the sender.

We do not accept liability in connection with computer virus, data corruption,
delay, interruption, unauthorised access or unauthorised amendment.
_______________________________________________________________________________


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

<<inline: image001.png>>

_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to