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

  • Home
  • SEARCH
  • 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 8556667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:24:17+00:00 2026-06-11T15:24:17+00:00

In WPF I am trying to put a context menu on the items of

  • 0

In WPF I am trying to put a context menu on the items of a listbox. When I run my app and right click on an item of the listbox the menu pops up for a split second and then closes again. I just can’t figure out what I am doing wrong.

This is the code I am using:

<ListBox Grid.Column="0" Name="lsbAddedElements" Width="150" Margin="3,3,3,3"
         SelectionMode="Multiple">
  <ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
      <Setter Property="ContextMenu">
        <Setter.Value>
          <ContextMenu>
            <MenuItem Header="Delete" Click="btnDeleteElement_Click"></MenuItem>
          </ContextMenu>
        </Setter.Value>
      </Setter>
    </Style>
  </ListBox.ItemContainerStyle>
</ListBox>

The listbox is bound to an ObservableCollection in code when the window is initialised, so item management is taken care of in code behind.

UPDATE:

I might need to add that thsi is part of an adin I am making for Excel. I am connecting to Excel using ExcelDNA then passsing the handle on to the WPF window that this code snippet is part of.
Could this be a reason for the context menu behaving in an unexpected way?

  • 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-06-11T15:24:19+00:00Added an answer on June 11, 2026 at 3:24 pm

    I think the problem is that the listbox item is getting focused. A simple solution to your problem is to set the context menu on the list box and enable/disable context menu items if the list box has a selected item.

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

Sidebar

Related Questions

I am trying to do an interface in WPF where a list of item
I started trying to implement drag-and-drop of virtual files (from a C# 4/WPF app)
I have a C#/WPF app. I am trying to create different versions that will
I am rather new to WPF. I'm trying to realize a chat app using
I'm working on a WPF app, using .NET 4. I'm also trying to wrap
I'm trying to put standard output from nmap into WPF window application (textbox exactly).
I'm trying to use a custom control in a WPF app, and I have
So I am very new to WPF and trying to bind or assign a
I'm writing a WPF application and trying to bind an image to my view
Im trying to look into using the WPF WriteableBitmap class to allow my application

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.