Posted 14 years ago
by Pat Maneely
-
Software Engineering Manager,
Cobham Aerospace

I'm trying to use Data Validation with the DataGrid without any success. I was wondering if you had any helpful hints or example code. I'm kinda stuck.
My Cell Style is:
<Style x:Key="CenterCellStyle" TargetType="{x:Type toolkit:DataGridCell}">
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
<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>
My DataGrid XAML is:
<datagrid:ThemedDataGrid Name="KeysDataGrid"
AutoGenerateColumns="False" GridLinesVisibility="All"
IsReadOnly="False"
SelectionMode="Single" SelectionUnit="FullRow"
ItemsSource="{Binding Keys}"
SelectedIndex="{Binding SelKeyIndex, Mode=TwoWay}"
MaxHeight="300"
CellStyle="{StaticResource CenterCellStyle}">
<datagrid:ThemedDataGrid.Columns>
...
<datagrideditors:DataGridMaskedTextColumn Header="Key" Mask="[0-9A-F]*"
Width="Auto" HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}"
Binding="{Binding Key,
ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}">
</datagrideditors:DataGridMaskedTextColumn>
I know that the DataValidation logic in my view ViewModel is being called and it returns an error string
But the Grid never indicates an error by changing the border red, nor is the Tooltip displayed.
My Cell Style is:
<Style x:Key="CenterCellStyle" TargetType="{x:Type toolkit:DataGridCell}">
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
<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>
My DataGrid XAML is:
<datagrid:ThemedDataGrid Name="KeysDataGrid"
AutoGenerateColumns="False" GridLinesVisibility="All"
IsReadOnly="False"
SelectionMode="Single" SelectionUnit="FullRow"
ItemsSource="{Binding Keys}"
SelectedIndex="{Binding SelKeyIndex, Mode=TwoWay}"
MaxHeight="300"
CellStyle="{StaticResource CenterCellStyle}">
<datagrid:ThemedDataGrid.Columns>
...
<datagrideditors:DataGridMaskedTextColumn Header="Key" Mask="[0-9A-F]*"
Width="Auto" HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}"
Binding="{Binding Key,
ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}">
</datagrideditors:DataGridMaskedTextColumn>
I know that the DataValidation logic in my view ViewModel is being called and it returns an error string
But the Grid never indicates an error by changing the border red, nor is the Tooltip displayed.