Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 251485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:35:54+00:00 2026-05-11T21:35:54+00:00

Interesting problem related to firing commands from context menu items… I want to fire

  • 0

Interesting problem related to firing commands from context menu items…

I want to fire a command to insert a row in my control, InsertRowCmd. This command needs to know where to insert the row.

I could use Mouse.GetPosition(), but that would get me the position of the mouse currently, which would be over the menu item. I want to get the origin of the context menu instead.

Does any one have any suggestions on how to pass the origin of the context menu as a parameter to the command?

Sample code:

<UserControl x:Name="MyControl">
<!--...-->
        <ContextMenu x:Name="menu">
            <MenuItem Header="Insert Row" Command="{x:Static customCommands:MyCommands.InsertRowCmd}" CommandParameter="?"/>
        </ContextMenu>
</UserControl>

My current ideas are as follows:

-Use click handler instead so that I can find the origin in code. The problem is that I would then have to handle enabling/disabling.

-Handle click event and save the origin of the context menu. Pass this saved information into the command. I have verified that click events fire before the command is executed.

Any ideas?

EDIT:

I’m using Josh Smith’s CommandSinkBinding to route the command handling into my ViewModel class. So the code that handles the command execution knows nothing about the view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:35:54+00:00Added an answer on May 11, 2026 at 9:35 pm

    You’ll need to use TranslatePoint to translate the top-left (0, 0) of the ContextMenu to a coordinate in the containing grid. You could do so by binding the CommandParameter to the ContextMenu and use a converter:

    CommandParameter="{Binding IsOpen, ElementName=_menu, Converter={StaticResource PointConverter}}"
    

    Another approach would be an attached behavior that automatically updates an attached readonly property of type Point whenever the ContextMenu is opened. Usage would look something like this:

    <ContextMenu x:Name="_menu" local:TrackBehavior.TrackOpenLocation="True">
        <MenuItem Command="..." CommandParameter="{Binding Path=(local:TrackBehavior.OpenLocation), ElementName=_menu}"/>
    </ContextMenu>
    

    So the TrackOpenLocation attached property does the work of attaching to the ContextMenu and updating a second attached property (OpenLocation) whenever the ContextMenu is opened. Then the MenuItem can just bind to OpenLocation to get the location at which the ContextMenu was last opened.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting algorithm problem here. The problem is in a way related
I've found an interesting problem in my WPF app related to a MultiDataTrigger not
I've just encountered an interesting problem related to Java serialization. It seems that if
I have a very interesting problem related to Deflate Compression, Apache (htaccess), and CSS
I've just encountered an interesting problem related to Java generics. I'd like to use
I am facing a critical and interesting problem in my azure related project. I
Interesting problem I ran into recently: I implemented a Stream class (a wrapping stream
Interesting problem I have here, usually I just round up/down respectively for my needs
We have an interesting problem with WCF binding and streaming transfer mode that we
So I have an interesting problem I am having issues with the jquery .load()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.