Reputation: 25287
Here's my code that is supposed to immitate WinForm's ErrorProvider for WPF:
<Window.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="True">
<Border BorderBrush="Red" BorderThickness="1" DockPanel.Dock="Left">
<AdornedElementPlaceholder />
</Border>
<Image Source="Images/dialog_error.png" Width="30" ToolTip="{Binding ElementName=adornedElement,
Path=AdornedElement.(Validation.Errors),
Converter={k:ValidationErrorsToStringConverter}}"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<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>
</Window.Resources>
I want it to display an error icon with a tooltip explaining what's wrong.
The error icon is being displayed, but the tooltip is missing.
What did I do wrong?
Upvotes: 1
Views: 540
Reputation: 3828
Looks like you forgot to set name on <AdornedElementPlaceholder />
. It should be <AdornedElementPlaceholder x:Name="adornedElement" />
otherwise your Binding ElementName=adornedElement
won't work
Upvotes: 4