【发布时间】:2017-05-17 20:15:21
【问题描述】:
我有一个简单的数据网格
<DataGrid x:Name="SmartTable"></DataGrid>
接下来,我在代码中初始化了列,并将其绑定到这个结构体:
public struct HddData
{
public Ellipse status { set; get; }
public string id { set; get; }
public string atribute { set; get; }
public string current { set; get; }
public string worst { set; get; }
public string treshhold { set; get; }
public string data { set; get; }
}
最后,我正在尝试使用 foreach 在表中插入行:
Ellipse good = new Ellipse();
Ellipse bad = new Ellipse();
good.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF64DD17"));
bad.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFD50000"));
SmartTable.Items.Add(new HddData
{
status = attr.Value.IsOK ? good : bad,
id = attr.Value.id,
atribute = attr.Value.Attribute,
current = attr.Value.Current.ToString(),
worst = attr.Value.Worst.ToString(),
treshhold = attr.Value.Threshold.ToString(),
data = attr.Value.Data.ToString("X"),
});
文本数据绑定良好,但 Ellipses 是单元格中的字符串类型,显示如下:
System.Windows.Shapes.Ellipse
我怎样才能不将它们显示为文本,而是显示为椭圆?
【问题讨论】:
-
学习XAML,这玩意是死路一条。你想要一个 DataGridTemplateColumn
-
@EdPlunkett:+1。 majukin:您需要对数据网格列进行一些模板化。