I have a ShellViewModel containing three properties of type ViewModel:
- One public
CurrentScreenproperty; - Two private:
FirstViewModelandSecondViewModelproperties.
FirstViewModel has an ObservableCollection<Foo> FooCollection and a SelectedFoo property of type Foo. It's two-way bound to a DataGrid in the View, which is a DataTemplate:
<DataGrid x:Name="setupsSensoresDataGrid"
ItemsSource="{Binding Source={StaticResource FooCollectionViewSource}}"
SelectedItem="{Binding SelectedFoo, Mode=TwoWay}">
....
The problem is, when I am at the first screen and select an item, when I go to the second screen and come back, the selection is lost.
I would like to know how to preserve selection (both visually and logically) while switching from one screen to the other.
It seems to me that the TwoWay data binding is de-selecting SelectedFoo when the View (a DataTemplate) is navigated away.