我遇到了类似以下问题:
WPF验证(IDataErrorInfo)和Tab焦点的问题
具有验证的TextBox在Tab更改时失去ErrorTemplate
AdornerDecorator
可以在同一实例的Window
中解决这个问题,但当Window
重新加载并切换到包含错误TextBox
的TabItem
时,ErrorTemplate
将不再显示。
<Window x:Class="Views.MyWindowView">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TabControl HorizontalAlignment="Stretch"
Height="Auto"
VerticalAlignment="Top"
Width="Auto"
SelectionChanged="TabItemChanged"
Name="MyTabControl">
<!-- Below, AdornerDecorator are added for the following reason:
the Validation.Error cues are painted in the Adorner Layer.
When tabs are switched, that layer is discarded. -->
<!-- The view 1 tab.-->
<TabItem Header="{Resx tab1_Header}"
Name="Tbi1">
<AdornerDecorator>
<vw:MyView1 DataContext="{Binding}"/>
</AdornerDecorator>
</TabItem>
<!-- The view 2 tab.-->
<TabItem Header="{Resx tab2_Header}"
Name="Tbi2">
<AdornerDecorator>
<vw:MyView2 DataContext="{Binding}"/>
</AdornerDecorator>
</TabItem>
</TabControl>
我尝试在代码后端的TabControl
SelectionChanged
上重新触发验证,但没有成功。
有什么想法吗?