I have a WPF ListBox in Extended SelectionMode.
What I need to do is bind the ListBox to an observable collection of a data item class, which is easy, but essentially, bind the IsSelected
status of each ListBoxItem to a boolean property in the respective data item.
And, I need it to be two-way, so that I can populate the ListBox with selected and unselected items from the ViewModel.
I've looked at a number of implementations but none work for me. They include:
- Adding a DataTrigger to the ListBoxItem's style and calling a state action change
I realise this can be done in code-behind with an event handler, but given the complexity of the domain it would be horribly messy. I'd rather stick to two-way Binding with the ViewModel.
Thanks. Mark