WPF DatagridTemplateColumn with Multiple column

Feb 3, 2012 at 5:06 AM
Edited Feb 3, 2012 at 5:09 AM

Hi,

I have a datagridtemplate column with multiple subcolumns my datagrid header template is something similar to this

<DataTemplate    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:Controls="clr-namespace:Presentation.Controls;assembly=Presentation" 
    xmlns:View="clr-namespace:View.Sale;assembly=SShell"     
    xmlns:ViewModel="clr-namespace:ViewModel"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >    
    <Grid         
        HorizontalAlignment="Stretch">
        <Grid.Resources>            
            <ItemsPanelTemplate x:Key="upnl">
                <UniformGrid 
                    Rows="1"
                    HorizontalAlignment="Stretch"/>
            </ItemsPanelTemplate>
            <Style 
                x:Key="hstl" 
                TargetType="DataGridColumnHeader">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBlock 
            Text="{Binding Caption}" 
            HorizontalAlignment="Center"
            TextTrimming="CharacterEllipsis"
            Margin="4,0,4,4"/>
        <Rectangle
            Grid.Row="1"
            HorizontalAlignment="Stretch"
            Height="1"
            Fill="Black"/>
        <ItemsControl 
            HorizontalAlignment="Stretch"
            Margin="4,4,0,4"
            Grid.Row="2" 
            ItemsSource="{Binding SubColumns}"             
            ItemsPanel="{StaticResource upnl}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Caption}"
                        TextTrimming="CharacterEllipsis"
                               Tag="{Binding}"
                        Margin="2,0,2,0"
                        HorizontalAlignment="{Binding DataType, Converter={StaticResource DTAC}}"
                        VerticalAlignment="Center">
                        <TextBlock.Triggers>
                           
                        </TextBlock.Triggers>
                    </TextBlock>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            
        </ItemsControl>
    </Grid>    
</DataTemplate>
 
My header will be something similear to this
		MainColumnHeading					
-------------------------------------------- 		RegularColumn1 RegularColumn2.........
SubColumn1 SubColumn2   (number of subcolumns are dynamic)
Datagrid sorting works fine for all regular columns.
Incase of the DatagridTemplateColumn the sorting dosent work, one way to make the sorting 
to work is to set the SortMemberPath.Setting SortMemberPath to a static value dosent help 
me because i needto set the sort memberpath based on the subcolumns which i have clicked. 
example if i click on subcolumn1 the grid should sort the results based on subcolumn1, 
clicking on subcolumn2 the grid should sort the results based on subcolum2 
(both subcolumn1 and subcolumn2 are belonging to the same DatagridTemplateColumn)
any hint on how to do this?