我有DataGrid
由用户动态制作。这意味着每次运行列都可能会非常不同。出于该原因,每个列都以编程方式添加。我需要为它添加一些DataTriggers
,因此认为这样可行:
Style style = new Style();
style.TargetType = typeof(DataGridTextColumn);
DataTrigger tg = new DataTrigger()
{
Binding = new Binding(value),
Value = "bad data"
};
tg.Setters.Add(new Setter()
{
Property = UIElement.VisibilityProperty,
Value = Visibility.Hidden
});
虽然在运行时它在IDE中没有出现任何错误,但它会崩溃并给我
'DataGridTextColumn' type must derive from FrameworkElement or FrameworkContentElement.
将DataTrigger
添加到DataGridTextColumn
以编程方式
答案 0 :(得分:2)
您需要使用typeof(DataGridCell)
。触发器应该应用于Cell
本身,而不是Column
。