WPF_DataGrid绑定Header
2025年1月5日小于 1 分钟
datagrid动态生成列的思路:先枚举所有的,然后把不需要的隐藏了
<DataGridTextColumn Header="{Binding DError}" IsReadOnly="True" Width="60"
Binding="{Binding ERROR4,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding DataContext.DErrorVisib,Source={StaticResource ProxyElement}}">
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding DataContext.DError,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay,
RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
public static readonly DependencyProperty AErrorProperty = DependencyProperty.Register("AError", typeof(string), typeof(AgentExamineFlowViewModel));
public string AError
{
get
{
return (string)GetValue(AErrorProperty);
}
set
{
SetValue(AErrorProperty, value);
}
}