C# – WPF ListView programmatically deselect item

cdata-bindinglistviewselection

I have used the following approach to bind IsSelected of my items to a Property: WPF ListView Programmatically Select Item

<ListView.ItemContainerStyle>
    <Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</ListView.ItemContainerStyle>

Now I am able to select my items in code behind by simple setting the IsSelected property to true. However I am not able to deselect items by setting the IsSelected property of my items to false.

Setting the items property IsSelected to true will trigger the ListViewSelectionChanged event. However setting the property IsSelected of an already selected item to false does not trigger the event. The property will be changed to false but the item remains selected within the ListView. I have also tried using Mode=TwoWay without any success.

I would appreciate any sort of help!

Thank you very much in advance,

Thomas

Best Answer

For OP or others looking to "programmatically" deselect a ListView. If your ListView rigged up as Single, Extended or Multiple you can always just:

YourlistView.Selecteditem = null;
Related Topic