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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:44:28+00:00 2026-05-14T14:44:28+00:00

I have a Contextmenu with a ListBox inside. Whenever I right click my control

  • 0

I have a Contextmenu with a ListBox inside. Whenever I right click my control and select a value from my contextmenu the last selected value stays marked and I can’t select that value again.

The idea is, that I may select the same value within the COntextmenu in order to turn a property on or off.

Should be quite basic, what am I missing?

Many Thanks,

EDIT: Thanks for the responses. I have tried to apply your ideas without success. I think the major problem is that MenuItems of a contextmenu have no ItemSource to be bound to a collection (e.g. PossibleValues as in this example).

May I insert my code for clarification:

    <Border.ContextMenu>
      <ContextMenu>
       <ContextMenu.ItemContainerStyle>
         <Style TargetType="{x:Type MenuItem}">
           <Setter Property ="Template">
             <Setter.Value>
                <ControlTemplate TargetType="{x:Type MenuItem}">
                  <ContentPresenter x:name="Header" ContentSource="Header" RecognizesAccessKey="True"/>
                </ControlTemplate>
             </Setter.value>
           </Setter>
         </Style>
       <ContextMenu.ItemContainerStyle>
       <ListBox BorderThickness="0" Width="35" Margin="0"
                SelectedItem="{Binding Path=Volume, Mode=TwoWay}
                DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext}" 
                ItemsSource="{Binding Path=PossibleValues}"/>
       </ContextMenu>
    </Border.ContextMenu>
  • 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-14T14:44:29+00:00Added an answer on May 14, 2026 at 2:44 pm

    Why do you have a ListBox in your ContextMenu? A ListBox allows you to select one item out of a list (or multiple items, if enabled). An example is the list of files in Explorer.

    A ContextMenu is an ItemsControl, ie. you can add an arbitrary number of items to it. So just add the items directly.

    EDIT: Both the ContextMenu and MenuItem are ItemsControl. They both have an ItemsSource property. So you could have the following:

    <ContextMenu
        DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext}"
        ItemsSource="{Binding Path=PossibleValues}"/>
    

    PossibleValues could be a collection of MenuItems. Each menuitem could look at follows (here in code), for example:

    var menuItem = new MenuItem();
    menuItem.Items.Add(new TextBlock { Text = "Something" });
    menuItem.Command = DoSomethingCommand;
    menuItem.CommandParameter = "identifier";
    

    EDIT2: Try something like the following. As command you could use one of the many implementations from MVVM helper libraries, such as DelegateCommand<> from Prism or SimpleCommand from Cinch.

    PossibleValues = new ObservableCollection<MenuItem>();
    
    // null value
    var nullMenuItem = new MenuItem();
    nullMenuItem.Items.Add(new TextBlock { Text = "Null" });
    nullMenuItem.Command = DoSomethingCommand;
    nullMenuItem.CommandParameter = null;
    PossibleValues.Add(nullMenuItem);
    
    // Values one to nine
    for (int i = 1; i < 9; i++)
    {
        var menuItem = new MenuItem();
        menuItem.Items.Add(new TextBlock { Text = i.ToString() });
        menuItem.Command = DoSomethingCommand;
        menuItem.CommandParameter = i;
        PossibleValues.Add(menuItem);
    }
    

    As for your execute handler of the command, something along the lines of:

    public void DoSomethingCommand_Execute(object commandParameter)
    {
        this.SelectedNumber = commandParameter as int?;
        // Or whatever you actually want to do in response to the selection.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to change the account that runs the… May 14, 2026 at 6:42 pm
  • Editorial Team
    Editorial Team added an answer Have a look at the example from Tutorial: Tasks using… May 14, 2026 at 6:42 pm
  • Editorial Team
    Editorial Team added an answer You can decode it as follows: QByteArray encoded = qMimeData->data("application/x-qabstractitemmodeldatalist");… May 14, 2026 at 6:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.