1
我有当细胞被分配到下面定义的自定义类一个DataGrid:WPF DataGrid绑定细胞背景颜色分配数据的属性对象
public class DataGridVariableWrapper : DependencyObject
{
public Variable TheVariable { get; set; }
public Brush BackgroundColor
{
get { return (Brush)GetValue(BackgroundColorProperty); }
set { SetValue(BackgroundColorProperty, value); }
}
public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.Register("BackgroundColor", typeof(Brush), typeof(DataGridVariableWrapper), new UIPropertyMetadata(null));
public DataGridVariableWrapper(Brush backgroundBrush, Variable theVariable)
{
this.BackgroundColor = backgroundBrush;
this.TheVariable = theVariable;
}
public override string ToString()
{
return TheVariable.Value.ToString();
}
}
我想有DataGridCell后台绑定转换为此数据包装类的BackgroundColor属性。我试过了:
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding DataGridVariableWrapper.BackgroundColor}" />
</Style>
</DataGrid.CellStyle>
但是背景颜色保持不变。我在这里做错了什么?
你试过'Value =“{Binding BackgroundColor}”'? – LPL 2013-05-13 17:51:54
这似乎工作,只需要弄清楚显示出来的小白色空间填充,而不是完整的背景填充。 – user2371475 2013-05-13 18:07:35
明白了,必须将单元格的边框厚度设置为0.如果您想让您的评论成为答案,我会将其标记为正确。 – user2371475 2013-05-13 18:12:58