Changing individual headers on DataGrid

Oct 28, 2014 at 3:01 PM
Hi

I was looking into changing the horizontal alignment of the header of a single column, but the Header property of DataGridTemplatedColumn.Header only accepts a string.
The ComboBox.Header in WinRT accepts an object so its possible to have a TextBlock as the header and change that.

This is what I would like to accomplish
<MtkControls:DataGrid.Columns>
    <MtkControls:DataGridTemplatedColumn
        Text="{Binding Qty}"
        Width="80">
        <MtkControls:DataGridTemplatedColumn.Header> 
 <!--Only accepts string-->
            <TextBlock
                Text="Quantity"
                HorizontalAlignment="Right"/>
        </MtkControls:DataGridTemplatedColumn.Header>
    </MtkControls:DataGridTemplatedColumn
</MtkControls:DataGrid.Columns>
Coordinator
Oct 29, 2014 at 7:15 AM
It should be easy to change this so that object is used.. Ill look into it in the next days
Coordinator
Nov 5, 2014 at 6:09 PM
Header is now objet in newest commit and can be a UI element => try latest code by downloading from "Source Code" page
Coordinator
Nov 5, 2014 at 6:19 PM
You may also need to change the datagrids HeaderTemplate so that the width of the header is not auto:
                <DataTemplate>
                    <Grid Background="Transparent">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <ContentPresenter Grid.Column="0" VerticalAlignment="Center" FontSize="26.667" Margin="15,0,15,0" Content="{data:Binding Header}" />
                        <StackPanel Grid.Column="1" Visibility="{Binding IsSelected, Converter={StaticResource vc}}" 
                                    VerticalAlignment="Center" HorizontalAlignment="Left">
                            <Path Data="M5,0 L0,10 L10,10 Z" Fill="White" Visibility="{Binding IsAscending, Converter={StaticResource vc}}"/>
                            <Path Data="M0,0 L5,10 L10,0 Z" Fill="White" Visibility="{Binding IsAscending, Converter={StaticResource nc}}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
Nov 6, 2014 at 9:49 AM
I tried this out on the DataGrid sample and works like a charm, great work as usual.