如何在逻辑删除中选择多选列表控件的选定值。我通过迭代语句[((System.Collections.Generic.List)(items))]来检索所选项的值,但我很擅长重新分配这些值,任何一个请帮我解决这个问题。这似乎是我的阻塞问题,我的市场提交只剩下可数天数。所以任何人请帮我解决这个问题。
答案 0 :(得分:3)
if (selectedItems != null && selectedItems.Count > 0) {
wordlist.IsSelectionEnabled = true;
ObservableCollection<Word> wrdlst = new ObservableCollection<Word>();
var vm = this.DataContext as wordsListVM;
wrdlst = vm.WordsList;
ItemContainerGenerator itemContainerGenerator = this.wordlist.ItemContainerGenerator;
foreach (Word word in wrdlst) {
if (word != null) {
foreach (string wordId in selectedItems) {
if (wordId == word.Id) {
DependencyObject visualItem = itemContainerGenerator.ContainerFromItem(word);
MultiselectItem multiselectItem = visualItem as MultiselectItem;
if (multiselectItem != null) {
multiselectItem.IsSelected = true;
}
}
}
}
}
}
答案 1 :(得分:1)
尝试listBox.SelectedItems.Add(item1);