0
使用SL5和Silverlight工具包Silverlight的 - 右鍵菜單多個項目中選擇
正在使用一個列表框,工作正常右鍵點擊:
private void Person_Click(object sender, RoutedEventArgs e)
{
Account account = ((MenuItem)sender).DataContext as Account;
UpdateText.Text = string.Format("Person selected on account: <{0}>", account.Username);
}
如果我選擇了多個列表框項目(的SelectionMode = 「擴展」),我只能引用Person_Click中的1個項目
問題:如何從上下文菜單中引用多個項目?
回答(爲未來的人!)
private void Person_Click(object sender, RoutedEventArgs e)
{
Account account = ((MenuItem)sender).DataContext as Account;
UpdateText.Text = string.Format("Person selected on account: <{0}>", account.Username);
//if multiple items are selected on right click this is how to reference them
List<int> selectedItemIndexes = new List<int>();
foreach (object o in AccountItemsT32.SelectedItems)
{
//selectedItemIndexes.Add(listBox.Items.IndexOf(o));
var x = o;
}
}