将DataGrid特定列单元格的背景颜色在后台设置

    xiaoxiao2022-07-12  138

    本例是将DataTable中的数据显示到DataGrid中。用List绑定的原理差不多。 XAML

    <DataGridTemplateColumn Width="80" Header="颜色"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Label Name="ColorLabel" Background="{Binding Color}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>

    后台

    DataTable DT1 = new System.Data.DataTable(); DT1.Columns.Add("Color", typeof(string)); DataRow row = DT1.NewRow(); row["Color"]="#111111";
    最新回复(0)