我遇到了一个问题,在第一次在我的wpf应用程序中加载一个新选项卡后的任何时候,无理由显示了IDataValidationInfo模板。
我的错误模板:
<ControlTemplate x:Key="ErrorTemplate">
<StackPanel Orientation="Horizontal">
<Border x:Name="border" BorderThickness="1.25"
BorderBrush="#FFDC000C" CornerRadius="2">
<Grid>
<AdornedElementPlaceholder x:Name="adorner"/>
</Grid>
</Border>
<Popup x:Name="placard"
AllowsTransparency="True"
PopupAnimation="Fade"
Placement="Top"
PlacementTarget="{Binding ElementName=adorner}">
<i:Interaction.Behaviors>
<behaviors:RepositionPopupBehavior/>
</i:Interaction.Behaviors>
<Popup.Style>
<Style TargetType="{x:Type Popup}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=errorShape, Path=IsMouseOver}"
Value="True">
<Setter Property="IsOpen" Value="True"/>
</DataTrigger>
<!-- Hides Popup when window is no longer active -->
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=IsActive}"
Value="False">
<Setter Property="IsOpen" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Popup.Style>
<Border x:Name="errorBorder"
Background="#FFDC000C"
Margin="0,0,8,8"
Opacity="1"
CornerRadius="4"
IsHitTestVisible="False"
MinHeight="24"
MaxWidth="267">
<Border.Effect>
<DropShadowEffect ShadowDepth="4"
Color="Black"
Opacity="0.6"
Direction="315"
BlurRadius="4"/>
</Border.Effect>
<TextBlock Text="{Binding ElementName=adorner, Path=AdornedElement.Validation.Errors[0].ErrorContent}"
Foreground="White"
Margin="8,3,8,3"
TextWrapping="Wrap"/>
</Border>
</Popup>
<Ellipse DockPanel.Dock="Right" Name="errorShape"
IsHitTestVisible="True"
Width="8" Height="8"
Margin="1,0,0,0"
StrokeThickness="1" Fill="Red" >
<Ellipse.Stroke>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFFA0404" Offset="0"/>
<GradientStop Color="#FFC9C7C7" Offset="1"/>
</LinearGradientBrush>
</Ellipse.Stroke>
</Ellipse>
</StackPanel>
</ControlTemplate>
因此,第一次将用户控件添加到选项卡时,它不会显示错误,因为填写了必填字段,所以不应该显示错误。
它应该看起来像这样,但它甚至不应该在上面的图片中触发,因为必填字段已填满。它也没有显示错误信息。
我正在加载填充这些字段异步的数据,如下所示。 为什么我第一次加载用户控件时它会工作?但是每次之后它都没有出现错误?有某种WPF缓存吗?装饰层是否没有被处理?
public exampleVM:IDataErrorInfo
{
public exampleConstructor()
{
Populate();
}
public async Task Populate()
{
//Async Call to DB, Fill in the VM Fields from result,
//EX:firstname,lastname
}
}