Question

I am having the text box in item template like below.

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

My Validation style are

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

But my validation trigger is not triggering above setup. Any help ? What i am missing here ?

Was it helpful?

Solution

Normally when we provide this kind of validation in WPF, we set the NotifyOnValidationError property to True on the Binding object. Try this:

<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}" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top