I created a WPF application by using MVVM design pattern. The MainView has a tabcontrol with two items each of them has a different View / ViewModel as showed in the following code
<TabControl>
<TabItem Header="Test 2" DataContext="{Binding CurrentTest2ViewModel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<AdornerDecorator>
<local:Test2View></local:Test2View>
</AdornerDecorator>
</TabItem>
<TabItem Header="Test 1" DataContext="{Binding CurrentTest1ViewModel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<AdornerDecorator>
<local:Test1View></local:Test1View>
</AdornerDecorator>
</TabItem>
</TabControl>
In one of the two ViewModels I used IDataErrorInfo Interface to validate properties. The corresponding View has the following Code
<StackPanel Orientation="Vertical">
<CheckBox HorizontalAlignment="Left" Width="80" Content="IsRed" IsChecked="{Binding IsRed, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsEnabled="{Binding IsEnabled}">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<AdornedElementPlaceholder />
<Label Content="{Binding Path=ErrorContent}" ToolTip="{Binding Path=ErrorContent}" />
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</CheckBox>
<CheckBox HorizontalAlignment="Left" Width="80" Content="IsGreen" IsChecked="{Binding IsGreen, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsEnabled="{Binding IsEnabled}">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<AdornedElementPlaceholder />
<Label Content="{Binding ErrorContent}" ToolTip="{Binding ErrorContent}" />
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</CheckBox>
</StackPanel>
When the first time the item is showed the validation discover an incorrect value for some property as I can see through breakpoints, but the error message does not appear on the screen. To reproduce the error message I need to select before correct values and after that when the values are not valid the error messages appears.
My question are:
1) How can I reproduce the error messages of validation from the first time that the item is showed on the screen? 2) Why do I have no problems if I use only the main view and not different views for any items?
Thank you very much in advance.