This is a WPF application.
Background:
I essentially have a Wizard application. The Wizard is initialized by providing a list of ViewModels. These ViewModels will create the appropriate view based on some DataTemplate in my XAML.
When clicking next or previous in the Wizard, the appropriate ViewModel will be set and the view will be loaded based on the DataTemplate.
This works fine.
Problem:
When I'm in a transitory state...meaning the new viewModel is being loaded, it appears there is a brief amount of time where the previous VIEW is still being referenced. Because of this, I get a bunch of BindingExpression errors where it says it cannot find a bunch of bindings which actually existed on the PREVIOUS viewModel.
SUMMARY: I'm loading a new view based on a DataTemplate. When that view is initially loaded, it appears to be out of sync with the actual viewModel. As such I get a bunch of binding expression errors.
Two questions:
- Any thoughts on how to fix this?
Any dangers to having these BindingExpression errors?
<wiz:WizardContent.Resources> <!--DataTemplates for defining views for this Wizard--> <DataTemplate DataType="{x:Type viewModel:Step1ViewModel}"> <view:Step1 DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=DataContext.CurrentPageVM}"/> </DataTemplate> <DataTemplate DataType="{x:Type viewModel:Step2ViewModel}"> <view:Step2 DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=DataContext.CurrentPageVM}"/> </DataTemplate> <DataTemplate DataType="{x:Type viewModel:Step3ViewModel}"> <view:Step3 DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=DataContext.CurrentPageVM}"/> </DataTemplate> </wiz:WizardContent.Resources> <ContentControl Content="{Binding Path=CurrentPageVM}"/>