Validation.HasError attached property
Asked Answered
R

1

6

Did I miss something?

1- Style

 <Style TargetType="{x:Type TextBox}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=Validation.HasError}" Value="true">
                <Setter Property="BorderBrush" Value="Blue" />
            </DataTrigger>
        </Style.Triggers>
        <Setter Property="MinWidth" Value="160" />
        <Setter Property="Margin" Value="0 7 0 0"/>
    </Style>

2 - Viewmodel implement IDataErrorInfo 3- textBox in view

 <TextBox x:Name="FirstName" Text="{Binding Person.FirstName,  UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true}"></TextBox>

3 - I use Caliburn MVVM

I got " BindingExpression path error: 'Validation' property not found on 'object' ''PersonWindowViewModel' (HashCode=38783181)'. BindingExpression:Path=Validation.HasError; DataItem='PersonWindowViewModel' (HashCode=38783181); target element is 'TextBox' (Name='FirstName'); target property is 'NoTarget' (type 'Object')"S

Rask answered 16/5, 2010 at 7:11 Comment(0)
M
14

Check out Beth Massi's article on implementing validation here

Basically, you've used a DataTrigger where you just need a Trigger

So:

<Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
        <Setter ... />
    </Trigger>
</Style.Triggers>
Macaroon answered 16/5, 2010 at 8:4 Comment(2)
I cannot tell you how many bloody times I have to come back here.Rosebay
@Will - lol. I love WPF, but I really do think some of it could be a little simpler :)Macaroon

© 2022 - 2024 — McMap. All rights reserved.