I am trying to collapse a column according to a condition with this code:
<DataGridTextColumn Header="MyColumn" Binding="{Binding MyProperty}">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Width" Value="0cm"/>
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=ThisView, Path=DataContext.MyboolProperty}" Value="true">
<Setter Property="Width" Value="2.5cm"/>
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
The problem is that the column is not complete collapsed, I can see a part of the column.
I have tried this code too:
<DataGridTextColumn Header="MyColumn" Binding="{Binding MyProperty}"
Width="0cm"
Visibility="Collapsed">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=ThisView, Path=DataContext.MyboolProperty}" Value="true">
<Setter Property="Width" Value="2.5cm"/>
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
In this case the column is collapsed as expected, but then if the property if the trigger is true, the column is still collapsed.
Also I have tried this option:
<DataGridTextColumn Header="MyColumn" Binding="{Binding MyProperty}">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=ThisView, Path=DataContext.MyboolProperty}" Value="true">
<Setter Property="Width" Value="2.5cm"/>
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=ThisView, Path=DataContext.MyboolProperty}" Value="false">
<Setter Property="Width" Value="0cm"/>
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
But the behavior is the same than first option, it is not full collapsed but it works when the property of the trigger is true.