Datagrid WPF modeling errors IDataErrorInfo

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)?

+3
2

, datagrid rowsytyle :

<DataGrid ...> 
<DataGrid.RowStyle> 
    <Style TargetType="DataGridRow"> 
        <Setter Property="ValidationErrorTemplate" Value="{x:Null}"/> 
    </Style> 
</DataGrid.RowStyle> 
<!-- ... --> 
</DataGrid> 
+3

- , TextBlock. , IDataErrorInfo datagrid, .

<Style x:Key="EditCellStyleError" TargetType="{x:Type TextBox}">
        <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>
    <Style x:Key="CellStyleError" TargetType="{x:Type TextBlock}">
        <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>

datagrid

<DataGridTextColumn .....
EditingElementStyle="{StaticResource EditCellStyleError}" ElementStyle="{StaticResource CellStyleError}"
</DataGridTextColumn>
+2

All Articles