Select item programmatically in WPF ListView

前端 未结 4 1778
[愿得一人]
[愿得一人] 2020-12-03 05:16

I\'m unable to figure out how to select an item programmatically in a ListView.

I\'m attempting to use the listview\'s ItemContainerGenerator, but it just doesn\'t s

4条回答
  •  星月不相逢
    2020-12-03 05:49

    Bind the IsSelected property of the ListViewItem to a property on your model. Then, you need only work with your model rather than worrying about the intricacies of the UI, which includes potential hazards around container virtualization.

    For example:

    
        
            
        
    
    

    Now, just work with your model's IsGroovy property to select/deselect items in the ListView.

提交回复
热议问题