[英]WPF Programmatically add DataGridTextColumn with DataTrigger
我有一个由用户动态组成的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
的正确方法是什么
您需要使用typeof(DataGridCell)
。 触发器应该应用于Cell
本身,而不是Column
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.