0
votes

I have a style trigger for create a tooltip with a validation error:

<Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                            Path=(Validation.Errors)[0].ErrorContent}"/>
                    <Setter Property="Validation.ErrorTemplate">
                        <Setter.Value>
                            <ControlTemplate>
                                <DockPanel>
                                    <Border BorderBrush="Red" BorderThickness="2" CornerRadius="2" Background="{x:Null}">
                                        <AdornedElementPlaceholder/>
                                    </Border>
                                </DockPanel>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
</Trigger>

I'm displaying first error (Validation.Errors)[0].ErrorContent), but I want to display the last one (the last is more prioritary, Framework textbox adds its validation errors at the end, for example strings not representing a date).

Thanks.

1

1 Answers

0
votes

Well, for one thing you could change the Path to all errors and add a ValueConverter that returns only the last message.

A lot of people also move validation completely to the view-model and ditch the validation rules, that way you have a lot of control over what exactly you expose to the view.