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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:25:17+00:00 2026-05-18T20:25:17+00:00

i want for my Listbox in WPF a contextmenu. I did it with a

  • 0

i want for my Listbox in WPF a contextmenu.
I did it with a contextmenu for the whole listbox, but you can richt-click to get the contextmenu even if you don’t click on a item.

I found something at google, but this didn’t work out.

I tried something like this:

<ListBox Margin="5" ItemsSource="{Binding}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}">
                <TextBlock.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="{Binding Name}" Click="MenuItemName_Click"/>
                        <MenuItem Header="{Binding Capital}"  Click="MenuItemCapital_Click"/>
                        <MenuItem Header="{Binding Population}" Click="MenuItemPopulation_Click"/>
                    </ContextMenu>
                </TextBlock.ContextMenu>
            </TextBlock>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

I tried it with a textblock like in the example, with other elements like in other tutorials, i tired it without and many other things- but nothing worked. No contextmenu for my listbox items 🙁

later i tried something like this:

 <ListBox.ItemTemplate>
     <DataTemplate>
         <ListBoxItem>
             <ListBoxItem.ContextMenu>
                 <ContextMenu>
                     <MenuItem/>
                 </ContextMenu>
             </ListBoxItem.ContextMenu>
         </ListBoxItem>
     </DataTemplate>
 </ListBox.ItemTemplate>

But it didn’t work too.

Can someone give me a hint/working example :)?

thank you

  • 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-18T20:25:18+00:00Added an answer on May 18, 2026 at 8:25 pm

    I would set the ContextMenu in the ListBoxItem‘s style, rather than in the DataTemplate:

    <ListBox Name="simpleListBox"
             ItemsSource="{Binding SimpleList}"
             DisplayMemberPath="Name">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="ContextMenu">
                    <Setter.Value>
                        <ContextMenu>
                            ...
                        </ContextMenu>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want for my Listbox in WPF a contextmenu. I did it with a
I want to get notified when an item in a ListBox gets clicked by
I want a ListBox full of items. Although, each item should have a different
I want set Listbox background to transparent but not working Is there any idea?
I want to override the selection behavior of ListBox Items. We can traverse through
Can I programatically set the position of a WPF ListBox's scrollbar? By default, I
I'm trying to create a transparent ListBox in a WPF application. I want the
I have a ObservableCollection that's bound to a ListBox in WPF. I want the
I don't know if the title express what I want. I have a ListBox
I'm styling the items in a WPF ListBox , and want to put a

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.