0
votes

I have use a textblock control to show error as below.

<TextBlock Text="{Binding ElementName=txtPassword, Path=(Validation.Errors)[0].ErrorContent}" 
               Visibility="{Binding ElementName=txtPassword,Path=Validation.HasError,Converter={StaticResource BoolToVisibilityConverter}}"
               Foreground="Red" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Left" />

Binding with text property is working fine but binding is not working with visibility property. I am getting below error in output window.

BindingExpression path error: 'Validation' property not found on 'object' ''PasswordBox' (Name='txtPassword')'. BindingExpression:Path=Validation.HasError; DataItem='PasswordBox' (Name='txtPassword'); target element is 'TextBlock' (Name=''); target property is 'Visibility' (type 'Visibility')

1
bool? a= txtLoging.GetValue(Validation.HasErrorProperty) as bool? ; this code is working in code behind. - Rudra
your xaml works for me, please update your question with a code-behind - lena

1 Answers

0
votes

There was an mistake in my code.

Visibility="{Binding ElementName=txtPassword,Path=Validation.HasError,Converter={StaticResource BoolToVisibilityConverter}}"

Above code should be like below.

Visibility="{Binding ElementName=txtPassword,Path=(Validation.HasError),Converter={StaticResource BoolToVisibilityConverter}}"

Because Validation.HasError is an attached property and when we are binding an attached property it should be covered with ().