我在项目模板中有文本框,如下所示。
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<WrapPanel Margin="2" >
<CheckBox IsHitTestVisible="false"
IsChecked="{Binding Status}"
Style="{StaticResource ResourceKey=TreeView_CheckBox_Style}" Visibility="Collapsed"></CheckBox>
<TextBox Text="{Binding Name, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Background="Transparent"
IsReadOnly="True"
BorderThickness="0" TextWrapping="Wrap"
MouseDoubleClick="TextBox_MouseDoubleClick"
LostFocus="TextBox_LostFocus"
Style="{StaticResource ResourceKey=ValidationErrorStyle}" >
</TextBox>
</WrapPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
我的验证风格是
<Style TargetType="TextBox" BasedOn="{StaticResource ResourceKey=TextBoxStyle}" >
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
</Trigger>
</Style.Triggers>
</Style>
但是我的验证触发器没有触发上面的设置。有帮助吗?我在这里缺少什么?
答案 0 :(得分:0)
通常,当我们在WPF中提供此类验证时,我们会在NotifyOnValidationError
对象上将True
属性设置为Binding
。试试这个:
<TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True}" Background="Transparent" IsReadOnly="True"
BorderThickness="0" TextWrapping="Wrap" MouseDoubleClick="TextBox_MouseDoubleClick"
LostFocus="TextBox_LostFocus" Style="{StaticResource ResourceKey=
ValidationErrorStyle}" />