I have a ListBox which is bound to an ObservableCollection.
I want to select a ListBoxItem when the mouse is released (means MouseLeftButtonUp) and as well as I need to toggle the selection. Means when the ListBoxItem is selected, selecting the item again will deselect the item and vice versa.
When the ListBoxItem is selected I need to apply the different style as well.
I have tried as the following.
I have used the DataTemplate and Style for the ListBoxItem, in the EventSetter, I have subscribed the event for MouseLeftButtonUp and in the event handler I am selecting the item and toggling it.
The issue is there are number of ways to select the item(Ctrl+arrow keys, Shift+arrow keys, arrow keys, Ctrl+A) and applying the style for the selection.
I have used the 'Name' property to store the previous state of the ListBoxItem(Tag property already used for other purpose of the Data binding in the DataTemplate).
How can we achieve this?
Any idea will be greatly appreciated.