0

我在项目模板中有文本框,如下所示。

             <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>

但是我的验证触发器没有触发上述设置。有什么帮助吗?我在这里缺少什么?

4

1 回答 1

0

通常,当我们在 WPF 中提供这种验证时,我们会将NotifyOnValidationError属性设置TrueBinding对象。试试这个:

<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}" />
于 2013-09-16T12:00:33.810 回答