gpt4 book ai didi

WPF:列表框取消选择

转载 作者:行者123 更新时间:2023-12-05 09:00:18 26 4
gpt4 key购买 nike

  1. 当用户点击我的单选 ListBox 中的项目时,该项目被选中。
  2. 当用户第二次点击某个项目时,除非他们按住 control 键,否则不会取消选择该项目。

将#2 更改为不需要控制键的推荐方法是什么?

最佳答案

确保选择模式是Multiple。通过选择多个:

you can use the mouse to select and deselect any item(s) you want with just a mouseclick. But if you want only 1 selected item at a time, you'll have to deselect the other items in code in the SelectionChanged event.

Source

Private Sub MainList_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
If e.AddedItems.Count > 0 Then
Dim valid = e.AddedItems(0)
For Each item In New ArrayList(MainList.SelectedItems)
If item IsNot valid Then MainList.SelectedItems.Remove(item)
Next
End If
End Sub

关于WPF:列表框取消选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2148937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com