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);
}
评论的代码没有运行,我不记得我昨天要问的是什么。抱歉这个糟糕的问题。我想我必须复制并粘贴错误的代码。请关闭这个问题。
答案 0 :(得分: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]);
}
当您选择任何项目时,它会立即被删除,那是您想要获得的吗?