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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:08:26+00:00 2026-05-19T01:08:26+00:00

I am trying to implement what I used to take for granted in Winforms

  • 0

I am trying to implement what I used to take for granted in Winforms applications. I am a Silverlight noob, so hopefully all this is elementary.

I have a listbox in a Silverlight 4 app. I’d like to do the following:

  1. Right-click on the listbox
  2. Have the item under the location where I click highlight itself
  3. I’d like a context menu to popup (with my own items in the context menu)

From my research so far, it appears that there is no ContextMenu construct in Silverlight, instead we have to build up a Grid/Canvas structure and attach it to a Popup object, which is what is then popped up.

My questions are as follows:

  1. To accomplish #2, I need some kind of hit test on the listbox. I can’t figure out how to do that and my google-fu isn’t helping.
  2. Once I do identify the index under the mouse, how do I actually select the item?
  3. Is there a reusable Context menu component somewhere that I can use? Extra credit if the component allows arbitrary sub-menus.
  • 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-19T01:08:26+00:00Added an answer on May 19, 2026 at 1:08 am

    I’ve been looking around for the same thing. I checked the Silverlight Control Toolkit at CodePlex and went through the samples (it’s a very handy resource) and here’s what I found to be the solution to what you asked:

    1. Create an ItemTemplate for your ListBox

    2. in the part that you want to be “right-clickable” of your ItemTemplate set the attached property ContextMenuService.ContextMenu that exists within the System.Windows.Controls.Input.Toolkit namespace

    3. add MenuItem controls to your ContextMenu and set the Click property to the corresponding click event handler

    4. in the event handler, get the DataContext from the sender (you can use that to find the corresponding element in the ListBox)

    5. to make that element Selected, just set the SelectedItem property in the list box to it

    6. Add any custom logic to the event handler

    There’s an example in the samples page, just go to “Input->ContextMenu” from the navigation pane.

    If you want something concise, Here’s a simplified example:

    <ListBox ItemsSource="{StaticResource People}"
                 Name="myListBox">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}">
                        <controlsInputToolkit:ContextMenuService.ContextMenu>
                            <controlsInputToolkit:ContextMenu>
                                <controlsInputToolkit:MenuItem Header="Show in MessageBox"
                                                               Click="show_Click" />
                            </controlsInputToolkit:ContextMenu>
                        </controlsInputToolkit:ContextMenuService.ContextMenu>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
    </ListBox>
    

    with:

    xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    

    for the code:

    private void show_Click(object sender, RoutedEventArgs e)
        {
            var person = ((MenuItem)sender).DataContext as Person;
            if (null == person) return;
            MessageBox.Show("My Name is: " + person.Name);
            myListBox.SelectedItem = person;
        }
    

    I hope this helps 🙂

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

Sidebar

Related Questions

I'm trying to implement the WMD editor used on StackOverflow to create some basic
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
We are trying to implement a REST API for an application we have now.
I'm trying to implement this extenstion of the Karplus-Strong plucked string algorithm, but I
I'm trying to implement my own qDebug() style debug-output stream, this is basically what
Am trying to implement a generic way for reading sections from a config file.
I am trying to implement string unescaping with Python regex and backreferences, and it

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.