Right-click on a Listbox in a Silverlight 4 app.

Posted by AngryHacker on Stack Overflow See other posts from Stack Overflow or by AngryHacker
Published on 2010-06-25T06:01:09Z Indexed on 2011/01/09 13:53 UTC
Read the original article Hit count: 181

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about menu