I'm using a ContentControl
im my WPF application to show different Views to the user.
<ContentControl Content="{Binding CurrentPageViewModel}"/>
By pushing a button the user can switch the value of CurrentPageViewModel
to another ViewModel object and, with the help of a DataTemplate
, switch to another View.
<DataTemplate DataType="{x:Type viewModel:AdministrationViewModel}">
<view:AdministrationView />
</DataTemplate>
<DataTemplate DataType="{x:Type viewModel:HealthViewModel}">
<view:HealthView />
</DataTemplate>
So far so good.
My problem starts whenever the View is switched. Then the old View is discarded and the Framework deletes/disposes the View object.
Grid sort settings are therefore lost and what's even worse, some of the Views values are set to null. The null values are propagated to my ViewModel by Databinding, which totaly messes up my ViewModel data!
How can I prevent the View object to be deleted/discarded?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…