I am using MVVM and have a datagrid with an editable column that I am doing to validate:
<DataGridTemplateColumn Header="Key" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<vw:NumericTextBox Text="{Binding Key, Mode=TwoWay,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
I added a style to show the error as a tooltip:
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors).CurrentItem.ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
So, the check is performed, and the cell is highlighted in red, and a tooltip is displayed with an error message.
I have 2 problems, firstly, when the user clicks the cell, the cell remains highlighted in red, but the tooltip does not appear when you hover. How do I make this work? The second problem is that next to the line there is an orange exclamation that I do not want. I assume this is due to some default style in the grid or row. How can I get rid of it (red outline is ok)?