【问题标题】:Colouring a cell in a data grid that has ItemSource set to a Data table为将 ItemSsource 设置为数据表的数据网格中的单元格着色
【发布时间】:2015-12-17 05:37:55
【问题描述】:

我有一个数据表,通过将数据网格的 ItemsSource 属性指定为在数据网格上查看

this.heatMap.ItemsSource = heatMapTable.DefaultView;

其中 heatmap 是 DataGrid,heatMapTable 是 DataTable。 我的问题是如何从该数据网格中选择一个单元格并在特定条件下对其进行着色。我知道我无法为数据表着色。请帮忙..

【问题讨论】:

  • 您可以为DataGridCell编写一个样式以根据DataTrigger应用背景颜色。
  • 不,在特定条件下,例如,如果单元格包含内容“y”,我想将 DataTable 中 DataRow 的所有单元格着色为黄色。

标签: c# wpf datagrid datatable


【解决方案1】:

使用 DataTriggers 检查您的情况。例如;

   <Style TargetType="DataGridCell">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Area}" Value="12345">
                <Setter Property="Background" Value="Yellow"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

【讨论】:

  • 我收到一个错误“使用 ItemsSource 之前项目集合必须为空”怎么办?
  • 您是如何使用 DataGrid 的,请显示 XAML 代码。
猜你喜欢
  • 2012-02-21
  • 2010-11-28
  • 1970-01-01
  • 2017-03-08
  • 2019-02-16
  • 2014-05-04
  • 2014-10-22
  • 2023-04-07
  • 2023-02-02
相关资源
最近更新 更多