DataGrid: Headers too small when not auto generated

Nov 18, 2008 at 4:05 PM
Hi

I am just getting started with using the DataGrid and am having an issue with it - I am binding the grid to a resource in the XAML - if I set AutoGenerateColumns to false then the header is only rendered at about 5 pixels high, unless a column is resized, at which point it sets it to the height as specified in the XAML.  If I set AutoGenerateColumns to True then it is rendered correctly, I have included the XAML below - any help on this would be appreciated as I have been staring at it all day with no success!

<ics:GetPublicationsResponse x:Key="publicationsCollection" />

 

 

<Style x:Key="dgHeaderStyle" TargetType="{x:Type dg:DataGridColumnHeader}">

 

 

<Setter Property="Background" Value="{StaticResource DataGrid_Style0_Header}" />

 

 

<Setter Property="Foreground" Value="White" />

 

 

</Style>

 

 

<Style x:Key="dgRowStyle" TargetType="dg:DataGridRow" >

 

 

<Style.Triggers>

 

 

<Trigger Property="AlternationIndex" Value="1" >

 

 

<Setter Property="Background" Value="{StaticResource DataGrid_Style0_Alt1}" />

 

 

</Trigger>

 

 

<Trigger Property="AlternationIndex" Value="0" >

 

 

<Setter Property="Background" Value="{StaticResource DataGrid_Style0_Alt0}" />

 

 

</Trigger>

 

 

</Style.Triggers>

 

 

</Style>

 


 

<dg:DataGrid x:Name="dgPublications" ItemsSource="{Binding Source={StaticResource publicationsCollection}, Path=Publications, Mode=TwoWay}"

 

 

AutoGenerateColumns="False" Margin="0"

 

 

Background="#80909090" AlternationCount="2"

 

 

ColumnHeaderHeight="25" ClipToBounds="True"

 

 

ColumnHeaderStyle="{StaticResource dgHeaderStyle}"

 

 

RowStyle="{StaticResource dgRowStyle}"

 

 

SelectionMode="Single"

 

 

SelectionUnit="FullRow"

 

 

GridLinesVisibility="All"

 

 

VerticalGridLinesBrush="DarkGray"

 

 

HeadersVisibility="All"

 

 

SelectionChanged="dgPublications_SelectionChanged" >

 

 

<dg:DataGrid.Columns>

 

 

<dg:DataGridTextColumn Header="Publication" Width="150" Binding="{Binding Title}" IsReadOnly="False"/>

 

 

<dg:DataGridTextColumn Header="Issue Number" Width="100" Binding="{Binding IssueNumber}" IsReadOnly="True" />

 

 

<dg:DataGridTextColumn Header="ISBN" Width="125" Binding="{Binding ISBN}" IsReadOnly="True"/>

 

 

<dg:DataGridTextColumn Header="Acronym" Width="125" Binding="{Binding Acronym}" IsReadOnly="True"/>

 

 

<dg:DataGridTextColumn Header="Date Created" Width="100" Binding="{Binding DateCreated, StringFormat=d}" IsReadOnly="True"/>

 

 

<dg:DataGridTextColumn Header="Date Delivered" Width="100" Binding="{Binding DateDelivered, StringFormat=d}" IsReadOnly="True"/>

 

 

</dg:DataGrid.Columns>

 

 

</dg:DataGrid>

 

Dec 12, 2008 at 4:04 PM
This is happening to me as well.  Setting the height works only in design time after that it reverts back to a default height.  Setting the minheight doesn't work and locks up VS2008 and has to re-start.

I also noticed this only works if AutoGenerateColumns="True" then the height works correctly.

Oddly enough there seems to be a property setting that starts this, if you start a new grid and don't change anything it will work properly.  Once you fiddle with a few properties this behavior seems to happen.  But haven't tracked it down to a specific pattern.


Feb 3, 2009 at 12:29 PM
Hello,

i encountered the same problem and hoped to fix it by updating to the January 2008 release. Alas, it didn't help.
To define a HeaderStyle did the trick:

<toolkit:DataGrid ...>
   
    <toolkit:DataGrid.Resources>
        <Style TargetType="toolkit:DataGridColumnHeader">
            <Setter Property="Height" Value="23"/>
        </Style>
    </toolkit:DataGrid.Resources>
    
    <toolkit:DataGrid.Columns>
        ...
    </toolkit:DataGrid.Columns>
</toolkit:DataGrid>