Nic*_*k B 11
MyListBox.SelectedItems.Add(item1);
MyListBox.SelectedItems.Add(item2);
.....
Run Code Online (Sandbox Code Playgroud)
你没有解释太多,希望你这样做的WPF方式......
IsSelected在您的数据项上创建一个属性,然后为您的ListBoxItems 提供样式,以便在IsSelected启用时选择它们:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</Style>
</ListBox.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)
然后更改数据项的属性,并引发OnPropertyChanged事件.