我有一个由用户动态组成的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”类型必须派生自 FrameworkElement 或 FrameworkContentElement。
以编程方式将 DataTrigger
添加到 DataGridTextColumn
的正确方法是什么
最佳答案
您需要使用typeof(DataGridCell)
。触发器应应用于Cell
本身,而不是Column
。
关于c# - WPF 以编程方式使用 DataTrigger 添加 DataGridTextColumn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35944772/