In my code I have a DataGrid
that I want to rotate for certain cases. Basically "rotating" just means switching the view mode of the DataGrid
(displaying columns horizontally or vertically).
The idea is to have a boolean variable coming from an interface. Depending on that, I want to activate/deactivate the transformed view. I think I will need like a converter or something..?
I just copy-pasted this code from another stackoverflow-question. I played a bit with it but I cannot answer questions to. I know, that following values HAVE TO be changed when rotating or not:
RotateTransform
Angle="-90"
MatrixTransform
Matrix="-1 0 0 1 0 0"
RotateTransform
Angle="-90"
ScaleTransform
ScaleX="1"
ScaleY="-1"
RotateTransform
Angle="-90"
ScaleTransform
ScaleX="1"
ScaleY="-1"
This is my XAML:
<DataGrid ItemsSource="{Binding Path=CurrentTable.DefaultView,IsAsync=True}"
AutoGenerateColumns="True"
AutoGeneratingColumn="DataGrid_AutoGeneratingColumn" SelectedItem="{Binding
SelectedItem}" IsReadOnly="False"
PreviewMouseRightButtonDown="DataGrid_PreviewMouseRightButtonDown"
PreviewMouseLeftButtonDown="DataGrid_PreviewMouseLeftButtonDown"
CellEditEnding="DataGrid_CellEditEnding" CanUserAddRows="False"
CanUserReorderColumns="False"
EnableColumnVirtualization="True" EnableRowVirtualization="True"
VirtualizingStackPanel.VirtualizationMode="Standard">
<DataGrid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="90"/>
<MatrixTransform Matrix="-1 0 0 1 0 0" />
</TransformGroup>
</DataGrid.LayoutTransform>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}"
BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
<Setter Property="LayoutTransform">
<Setter.Value>
<TransformGroup>
<RotateTransform Angle="-90"/>
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="LayoutTransform">
<Setter.Value>
<TransformGroup>
<RotateTransform Angle="-90"/>
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Setter.Value>
</Setter>
</Style>
</DataGrid.CellStyle>
</DataGrid>
Could you help me? I really do not know, where to start and what to start with.
Edit 1:
With big help of @thatguy I was able to rotate my DataGrid
. I wonder how I can change the weird sizes of the cells after being rotated.
An example of my code.
Before rotating:
After rotating: