I have two views of some data: now a list view (a ListBox , but I mean switching to a ListView ) and a fantastic graphical view on the map. In any view, the user can click an object and it will be selected in both views. A multi selector is also possible, so each instance of ViewModel has its own IsSelected property.
I am currently binding ListBoxItem.IsSelected to ViewModel.IsSelected , but this works correctly if the ListBox NOT virtualized ( see here ). Unfortunately, disabling virtualization degrades performance, and my application has become too slow.
So I need to turn on virtualization again. To save the ViewModel.IsSelected property of items off-screen, I noticed that the ListBox and ListView have a SelectionChanged event that I can (presumably) use to propagate the selection state from the ListBox/ListView to the ViewModel .
My question is: how do I propagate the state of choice in the opposite direction? The SelectedItems ListBox/ListView property is read-only! Suppose the user clicks on an item in a graphical representation, but it is off the wrt list screen. If I just installed ViewModel.IsSelected , then the ListBox/ListView will not be aware of the new selection, and as a result, it will not be able to deselect this item if the user clicks on it another item in the list. I could call ListBox.ScrollIntoView from ViewModel , but there are a few problems:
- In my user interface, you can actually select two items with one click if they are located in the same place graphically, although they can be in completely different places in the
ListBox/ListView . - It breaks the isolation of the ViewModel (my ViewModel does not fully know WPF, and I would like to save it that way.)
So my dear WPF experts, any thoughts?
EDIT: I switched to Infragistics management and used an ugly and rather slow solution. The fact is that I no longer need an answer.
Qwertie Nov 11 '11 at 1:20 2011-11-11 01:20
source share