c# - Silverlight Datagrid : Changing cell styles, 基于值

标签 c# silverlight datagrid cells

我有一些数据。如果该数据满足特定条件,我想遍历该数据并更改单元格(例如 - 背景颜色)。不知何故,我无法弄清楚如何在 Silverlight 中完成这件看似简单的事情。

最佳答案

这是稍旧的代码(来自 RTM 之前的代码),但可以满足您的需求。它检查一行中某个对象的一些数据,然后相应地设置该行的颜色。

XAML:

<my:DataGrid x:Name="Grid" Grid.Row="1" Margin="5" GridlinesVisibility="None" PreparingRow="Grid_PreparingRow">
    <my:DataGrid.Columns>
        <my:DataGridTextBoxColumn 
            DisplayMemberBinding="{Binding Cheese}" 
            Header="Cheese"></my:DataGridTextBoxColumn>
        <my:DataGridTextBoxColumn 
            DisplayMemberBinding="{Binding Biscuit}" 
            Header="Biscuit"></my:DataGridTextBoxColumn>
    </my:DataGrid.Columns>
</my:DataGrid>

代码:

this.Grid.AlternatingRowBackground = null; 

private void Grid_PreparingRow(object sender, DataGridRowEventArgs e)
{
    CheesyClass c = e.Row.DataContext as CheesyClass;
    if (c != null && c.Cheese == "cheddar")
    {
       e.Row.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 125, 125));
    }
}

关于c# - Silverlight Datagrid : Changing cell styles, 基于值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/377030/

相关文章:

c# - 在 CellEditEnding 事件上修改 DataGrid 单元格值

c# - 有没有办法在 C# 中打印计算的时间格式字符串?

c# - 使用 Azure 函数 c# 将 json 存储在 blob 存储上

c# - 在页面之间导航期间显示 Progressring

c# - 为什么取消订阅DataContextChanged会因Collection Modified而导致InvalidOperation异常

c# - RichTextBox 不显示我的所有文本。

silverlight - 找到更好的控制

c# - C# 中相互引用对象的垃圾回收

c# - 值不能为空。参数名称 : dataSource. 编辑数据网格并保存到数据库

c# - WPF DataGrid 列标题使用自定义样式调整大小