【问题标题】:Style background of Cell in EditMode in RadGridViewRadGridView中EditMode中单元格的样式背景
【发布时间】:2016-07-28 12:29:26
【问题描述】:

我想在 RadGridView 中设置一个单元格的样式,因此每当单元格进入编辑模式时,背景颜色就是例如黄色。

<telerik:RadGridView x:Name="Name" SelectionUnit="Cell">
  <telerik:RadGridView.Resources>
       <Style  TargetType="telerik:GridViewCell">
                <Style.Triggers>
                    <Trigger Property="IsInEditMode" Value="True">
                        <Setter Property="Background" Value="Yellow"/>
                    </Trigger>
                </Style.Triggers>
       </Style>
  </telerik:RadGridView.Resources>
</telerik:RadGridView>

这没有任何作用。

【问题讨论】:

  • 你确定背景没有被单元格中的元素隐藏吗?意思是,如果一个单元格在编辑模式下显示一个文本框,它是否会扩展到单元格的所有边框并隐藏它下面的内容?
  • 它是隐藏的。当我双击一个单元格时,单元格变为白色文本框,其中的数字标记为蓝色。有没有办法改变白色?
  • &lt;TextBox Background="Yellow"/&gt;
  • 谢谢!!帮助

标签: c# wpf vb.net styles radgridview


【解决方案1】:

如 cmets 中所述,GridViewCell 在可编辑时会显示一个TextBox,它会占用GridViewCell 可用的整个空间;所以设置GridViewCell 的背景没有任何作用,因为你看不到GridViewCell 的背景。解决方法是在GridViewCell是可编辑的时候改变控件显示的背景,因此我们需要改变TextBoxBackground

RadGridView 中执行以下操作:

<telerik:RadGridView.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Background" Value="LightYellow"/>
        </Style>
</telerik:RadGridView.Resources>

它将每个选择编辑单元格的背景颜色更改为LightYellow

【讨论】:

  • 不只是发布答案添加更多描述。它将帮助提出问题的人理解您的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-08
  • 2012-08-25
  • 1970-01-01
  • 2010-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多