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 6733357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:45:32+00:00 2026-05-26T10:45:32+00:00

In our application we have a central resource where we define all system-wide menus

  • 0

In our application we have a central resource where we define all system-wide menus for items. These menu items are already bound to system-wide-defined commands for our objects. For instance, anywhere in the app where we are dealing with a ‘Foo’ object, we simply attach the ‘FooContextMenu’ resource. Works great.

BUT… one of the menus defines a submenu representing enumeration values and as such, we want the apropriate menu item to be checked depending on the value of the enum-typed property on the object. For instance, everywhere in the UI that displays a ‘Foo’ object, we want to show this context menu…

FooContextMenu
    |__First Foo command
    |__Set Foo Encoding
    |   |__EnumValueA
    |   |__EnumValueB
    |   |__EnumValueC // <-- Show checkbox if 'Foo.SomeEnumProp' == 'C'
    |   |__EnumValueD
    |__Other Foo command
    |__Last Foo command

Now again, since the commands and context menu resources are defined centrally, they all work to execute the code just fine. What we can’t figure out is how to globally deal with that checkbox. While we could add the ‘ContextMenuOpening’ code everywhere, that’s the problem. We have to add that everywhere, but I can’t imagine that’s how you have to do it.

I’m sure I’m missing something blindingly obvious considering this is basic Windows app (any OS actually) behavior, but I just can’t see it. (I’m wondering if the context menus pick up the data context of the item they’re attached to and I can do simple bindings, but that’s just a guess.) Thoughts?

  • 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-26T10:45:33+00:00Added an answer on May 26, 2026 at 10:45 am

    The ContextMenu behaves a bit differently with regard to the DataContext.

    <ContextMenu>
          <MenuItem Header="Foo" 
                    Command="{Binding FooCommand}" 
                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItems}"/>
    </ContextMenu>
    

    The DataContext of the MenuItem within the ContextMenu will be that of the parent, which is the ViewModel which most likely exposes the collection which the ListBox.ItemsSource is bound to in the above example.

    If you wanted to work directly with the Model being represented within the listing of items, you would need to use the relative pathing of the given item as seen above in the CommandParamter scenario. If you want to simply expose the common command with your ViewModel, then you can use the binding as you are used to as the DataContext will be the ViewModel representing the listing of items.

    Specific to your example it could look something like this if you were keeping the common behavior within the ViewModel, versus the Model.

    <ContextMenu>
          <MenuItem Header="Foo">
               <CheckBox 
                     Visibility="{Binding Path=YourProperty, 
                     Converter={StaticResource BooleanToVisibilityConverter}}">
                     My CheckBox
               </CheckBox>
          </MenuItem>
    </ContextMenu>
    

    You could then have your property within your ViewModel call out to a Service where you have everything centralized. If you need the Model to make your decision within the converter, you will need to use the relative pathing to get the SelectedItem to pass as a parameter.

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

Sidebar

Related Questions

Our application is interfacing with a lot of web services these days. We have
In our application we have style sheets to define common colors etc… I wrote
Our legacy web application heavily uses stored procedures. We have a central interface through
in our application we have a Java applet running inside a .NET browser control.
In our application we have a little query that looks like this: var selectedAgents
In many places in our application we have code like this: using(RAPI rapi =
In our application we sometimes have to make minor GUI modifications for different customers:
In our web application we have a directory which resides outside of the project.
We have two tables in our application that both have a ShowOrder column. We
We have an application that downloads some files in the background. Our application pops

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.