0
for (int x = added_signals_listbox.SelectedItems.Count - 1; x >= 0; x--)
      {
        SignalViewModel SelectedItem = added_signals_listbox.SelectedItems[x] as SignalViewModel;
        int SelectedItemIndex = added_signals_listbox.Items.IndexOf(SelectedItem);
        //ListBoxItem container = added_signals_listbox.SelectedItems.Item.ContainerFromItem(SelectedItem) as ListBoxItem;
        //int SelectedItemIndex = added_signals_listbox.ItemContainerGenerator.IndexFromContainer(container);
        _GraphViewerViewModel.AddedSignals.RemoveAt(SelectedItemIndex);
      } 

注释的代码没有运行,我不记得我昨天试图问什么。对不起这个可怜的问题。我想我一定是复制并粘贴了错误的代码。请关闭问题。

4

1 回答 1

1

以列表框为例

 <ListBox Name="listbox" SelectionChanged="changed" SelectionMode="Multiple">
        <ListBox.Items>
            <ListBoxItem>one</ListBoxItem>
            <ListBoxItem>two</ListBoxItem>
        </ListBox.Items>
    </ListBox>   

 private void changed(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
        for (int index = 0; index < listbox.SelectedItems.Count; index++)
            listbox.Items.Remove(listbox.SelectedItems[index]);
    }

当您选择任何项目时,它将立即被删除,那是您想要获得的吗?

于 2013-09-26T05:37:42.910 回答