I have a DataGrid
whose ItemsSource
is bound to a System.Data.DataTable
. This DataTable
is filled at runtime with some text columns and some boolean columns. As expected, the text columns are displayed as DataGridTextColumn
and the boolean ones are displayed as DataGridCheckBoxColumn
. No problem so far. Now I want the column headers of the checkbox columns to be displayed as vertical. So I defined a style like this:
<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
<Style.Triggers>
<!--<Trigger Property=??? Value=???>
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="270"/>
</Setter.Value>
</Setter>
</Trigger>-->
</Style.Triggers>
</Style>
The problem is -as commented in the code, I don't know what kind of trigger I should use for the style in order to be applied only to the DataGridCheckBoxColumn
s and not other types of columns. Any ideas?
I have checked your code, why did you want to use Trigger?
Please check my following code if it's that you want.
Best Regards,
Messi
To fulfill both requisites:
You could resort to Attached Behaviour:
DataGridColumnsBehavior.cs
XAML
The timing is controlled by a Flip property. Every time Collection is changed, set Flip to false and then to true again. The Columns are iterated and the Headers of the DataGridCheckBoxColumns are flipped. Note the way this is implemented setting Flip to false does nothing, so the Headers aren't flipped back.
EDIT
Just learned about a shorter method, using the AutoGeneratingColumn event:
Handler in partial class