views:

266

answers:

1

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

+2  A: 

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