WPF Datagrid Cell with Validation Error Style

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

I am trying to change the default style of a DataGridCell (within a WPF Toolkit DataGrid) when there is a validation error. The default is a red border. How can I put my own template?

Thanks.

回答1:

Try this:

<!-- Cell Style -->     <Style x:Key="CellErrorStyle" 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}"/>                 <Setter Property="Background" Value="Yellow"/>             </Trigger>         </Style.Triggers>     </Style> 

And use it:

        <DataGrid.Columns>             <DataGridTextColumn                  ElementStyle="{StaticResource CellErrorStyle}">             </DataGridTextColumn>         </DataGrid.Columns> 


回答2:

There's a nice tutorial from Diederik Krols that does exactly what you're asking for the WPF Toolkit DataGrid.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!