Datagrid headers rotation

Nov 26, 2008 at 3:41 PM
Hi

I'd like to rotate the headers of my datagrid, as the columns are (have to be) very narrow.

I try something like this below, but the type "DataGridColumnHeader" is not found , error is
"The type reference cannot find a public type named 'DataGridColumnHeader'"

As I use the datagrid in my app, I think the references are ok.

If I try for syntactic purposes to use "DataGridCell" instead, it compiles, but of course does not do the right thing.

Any clues

Regards
Klaus

      <dg:DataGrid x:Name="dgData"
                   AlternationCount="2"
                   CanUserAddRows="False"
                   CanUserSortColumns="False"
                   AlternatingRowBackground="LightBlue"
                   AutoGenerateColumns="True"
                   IsSynchronizedWithCurrentItem="False"
                   Background="Transparent"
                   RowHeaderWidth="25"
                   RowBackground="White"
                   BorderThickness="0"
                   BorderBrush="White"
                   SelectionUnit="CellOrRowHeader"
                   ItemsSource="{Binding}"
                   FrozenColumnCount="1">
        <dg:DataGrid.Resources>
          <Style TargetType="{x:Type dg:DataGridColumnHeader}">
            <Setter Property="ContentTemplate">
              <Setter.Value>
                <DataTemplate>
                  <StackPanel>
                    <TextBlock Text="{Binding}">
                      <TextBlock.RenderTransform>
                        <RotateTransform Angle="270"/>
                      </TextBlock.RenderTransform>
                    </TextBlock>
                  </StackPanel>
                </DataTemplate>
              </Setter.Value>
            </Setter>
          </Style>
        </dg:DataGrid.Resources>
      </dg:DataGrid>
Nov 26, 2008 at 4:22 PM
Hi,

How have you declared the dg namespace? is it as follows:

xmlns:dg="clr-namespace:Microsoft.Windows.Controls"

DataGridColumnHeader is in the Microsoft.Windows.Controls.Primitives CLR namespace so this could be the problem. If this is the case,  try the following:

xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"

it is effectively aliased to both of the above CLR packages.

Colin E.
--
http://wpfadventures.wordpress.com/ - watch this space!


Nov 26, 2008 at 4:50 PM
Colin
thanks for this, works but ... almost:
I'd like to change the height of my header row to fit the column headers which now are too long, I tried using the xaml below but the height does not change
Thanks a lot
Klaus

<</FONT>Style TargetType="{x:Type dg:DataGridColumnHeader}">

<</FONT>Setter Property="ContentTemplate">

<</FONT>Setter.Value<FONT color=#0000ff size=2>>

<</FONT>DataTemplate<FONT color=#0000ff size=2>>

<</FONT>StackPanel<FONT color=#0000ff size=2>>

<</FONT>TextBlock Text="{Binding}">

<</FONT>TextBlock.RenderTransform<FONT color=#0000ff size=2>>

<</FONT>RotateTransform Angle="270"/>

</TextBlock.RenderTransform<FONT color=#0000ff size=2>>

</TextBlock

</StackPanel<FONT color=#0000ff size=2>>

</DataTemplate<FONT color=#0000ff size=2>>

</Setter.Value<FONT color=#0000ff size=2>>

</Setter<FONT color=#0000ff size=2>>

<</FONT>Setter Property="Height" Value="Auto">

</Setter<FONT color=#0000ff size=2>>

</Style<FONT color=#0000ff size=2>>



From: ColinEber [mailto:notifications@codeplex.com]
Sent: Mittwoch, 26. November 2008 17:23
To: Klaus Wiesel
Subject: Re: Datagrid headers rotation [wpf:40878]

From: ColinEber

Hi,

How have you declared the dg namespace? is it as follows:

xmlns:dg="clr-namespace:Microsoft.Windows.Controls"

DataGridColumnHeader is in the Microsoft.Windows.Controls.Primitives CLR namespace so this could be the problem. If this is the case, try the following:

xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"

it is effectively aliased to both of the above CLR packages.

Colin E.
--
http://wpfadventures.wordpress.com/ - watch this space!


Nov 26, 2008 at 5:14 PM
Hi,

You can apply transforms at two different stages:

  • Layout transforms - these occur before the layout of the screen is arranges
  • Render transforms - these occur after.
Try using a Layout transform instead.

Regards, Colin E.
--
http://wpfadventures.wordpress.com/
Nov 26, 2008 at 5:34 PM
<link rel="stylesheet" type="text/css" href="/Css/Wiki.css" />
Bingo!!!
Super Tip
Regards
Klaus