WPF ListBoxItem selection problem

后端 未结 3 1536
忘了有多久
忘了有多久 2020-12-09 10:01

I have a listbox where the items contain checkboxes:


    

        
3条回答
  •  暖寄归人
    2020-12-09 10:40

    In your use case it would be way simpler to use a ItemsControl instead of a list box. A ItemsControl is similar to a Listbox except that it doesn't contain the automatic selection behaviour. Which means that using it to host a list of what are essentially checkboxes is very simple and you don't have to workaround the ListBox's selection behaviour.

    Simply switching to ItemsControl will give you exactly what you need:

    
        
            
                
            
        
    
    

    You can click on text to check checkboxes (default behavior) and you can use the keyboard too without having to wire up any event handlers.

提交回复
热议问题