造型DataGridCell错误模板 [英] Styling DataGridCell Error Template

查看:117
本文介绍了造型DataGridCell错误模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在TextBoxDataGridColumn上的TextBox在单元格值无效时显示红色背景。我没有能够摆脱烦人的默认红色边框。

I would like the TextBox on my TextBoxDataGridColumn to display a red background when the cell value is invalid. I haven't been able to get rid of the annoying default red border.

如何做?

谢谢!

推荐答案

只需将此样式添加到您的控制资源,它应该适用于您控制中的所有文本框,然后 - / p>

Simply add this style to your Control resources, it should work for all the textboxes in your control then -

<Style x:Key="{x:Type TextBox}" TargetType="TextBox">
  <Setter Property="Validation.ErrorTemplate">
    <Setter.Value>
      <ControlTemplate>
        <Border Background="Red" Opacity="0.5" ToolTip="{Binding ElementName=adorner,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
           <AdornedElementPlaceholder Name="adorner"/>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

这篇关于造型DataGridCell错误模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆