I was looking for the same thing. I checked the Silverlight Control Toolkit in CodePlex and went through the samples (this is a very convenient resource), and here is what I found a solution for which you asked:
Create an ItemTemplate for your ListBox.
, " " ItemTemplate, ContextMenuService.ContextMenu, System.Windows.Controls.Input.Toolkit
MenuItem ContextMenu Click
, DataContext ( ListBox)
Selected, SelectedItem
, "Input- > ContextMenu" .
- , :
<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>
:
xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
:
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;
}
, :)