I am trying to make a nice error message for a text box. The text box:
<DockPanel DockPanel.Dock="Top">
<Label Content="Name: "/>
<TextBox DockPanel.Dock="Top" Text="{Binding Name, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource textBoxInError}">
</TextBox>
</DockPanel>
I started with a tooltip. Error style for the textbox:
<!-- Style for the error tooltip for fields -->
<Style x:Key="textBoxInError" TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
That is not sufficient, a better message is required. With this solution the error is not visible until you hover the field:
So I found that I can create another node that will receive the error message from the text box:
<DockPanel DockPanel.Dock="Top">
<Label Content="Name: "/>
<TextBox DockPanel.Dock="Top" Name="editNodeName" Text="{Binding Name, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource textBoxInError}">
</TextBox>
<TextBlock Text="{Binding (Validation.Errors)[0].ErrorContent, ElementName=editNodeName}" TextWrapping="Wrap"/>
</DockPanel>
That looks like this - very ugly and it somehow compressed the text box:
Here's a mockup of what I'd like instead, this should not require mouse hover to be visible:
It doesn't have to be exactly like that, but it shouldn't compress the checkbox or otherwise intrude in the form and it should not be visible when there is no error.
Can I float an error message text next to the field? Maybe somehow bind the position to the field's position using binding?