WPF Listbox remove selection by clicking on blank space

后端 未结 4 660
旧时难觅i
旧时难觅i 2021-01-03 03:49

I have a wpf listbox with a custom item template which contains a rectangle. The each item in the listbox can be selected (only one at a time). I w

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 04:02

    To assure that only one item is selected put this in the listbox:

    SelectionMode="Single"
    

    then for the unselect when clicking somewhere, you can try to check this events

    PreviewMouseLeftButtonUp
    LostFocus()
    

    Regards,

提交回复
热议问题