Silverlight - 上下文菜单选择了多个项目

时间:2012-11-02 14:19:06

标签: silverlight

使用SL5和Silverlight Toolkit

使用右键单击ListBox,工作正常:

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);
        }

如果我选择了多个ListBox项(SelectionMode =“Extended”),我只能引用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;
            }
        }

1 个答案:

答案 0 :(得分:0)

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;
            }
        }