Datagrid + Sorting by Header

Mar 11, 2010 at 6:50 PM
Edited Mar 11, 2010 at 6:52 PM
        <datagrid:DataGrid FontSize="12"  Margin="0,5,0,5" 
                           AutoGenerateColumns="False" 
                           AlternationCount="2" 
                           AlternatingRowBackground="{DynamicResource DataBrush}" 
                           IsReadOnly="True"
                           Background="White" BorderBrush="Black"
                           x:Name="ViewList"                           
                           SelectionUnit="FullRow"
                           ColumnHeaderStyle="{DynamicResource DataGridHeader}" 
                           VerticalScrollBarVisibility="Visible"
                           HorizontalGridLinesBrush="{DynamicResource BorderBrush}" 
                           VerticalGridLinesBrush="{DynamicResource DataBrush}" 
                           CanUserResizeRows="False" 
                           
                           CanUserResizeColumns="False" ItemsSource="{Binding List, Mode=Default}" HorizontalScrollBarVisibility="Disabled" Sorting="ViewList_Sorting">
            <datagrid:DataGrid.GroupStyle>
                <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <datagrid:DataGridRowsPresenter/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </datagrid:DataGrid.GroupStyle>
            <datagrid:DataGrid.RowDetailsTemplate>
                <DataTemplate>

                </DataTemplate>
            </datagrid:DataGrid.RowDetailsTemplate>
            <datagrid:DataGrid.Columns>
                <datagrid:DataGridTextColumn x:Name="Month"
                                             Binding="{Binding Key}"
                                             Width="*" />
                <datagrid:DataGridTextColumn x:Name="ThisYear" 
                                             Header="This Year" 
                                             HeaderStyle="{StaticResource RightAlignedColumnHeaderStyle}"
                                             Binding="{Binding VolumeActual, Converter={StaticResource ThousandSeparator}}" ElementStyle="{StaticResource RightAlignStyle}" 
                                             Width="0.2*" />
                <datagrid:DataGridTextColumn x:Name="LastYear"  
                                             Header="Last Year" 
                                             HeaderStyle="{StaticResource RightAlignedColumnHeaderStyle}"
                                             Binding="{Binding VolumeLastYear, Converter={StaticResource ThousandSeparator}}" ElementStyle="{StaticResource RightAlignStyle}" 
                                             Width="0.2*" />
                <datagrid:DataGridTextColumn x:Name="GrowthLitre" 
                                             Header="Growth (litres)" 
                                             HeaderStyle="{StaticResource RightAlignedColumnHeaderStyle}"
                                             ElementStyle="{StaticResource RightAlignStyle}" Width="0.3*" >
                    <datagrid:DataGridTextColumn.Binding>
                        <MultiBinding Converter="{StaticResource GrowthConverterLitre}">
                            <Binding Path="VolumeActual" />
                            <Binding Path="VolumeLastYear" />
                        </MultiBinding>
                    </datagrid:DataGridTextColumn.Binding>
                </datagrid:DataGridTextColumn>
                <datagrid:DataGridTextColumn x:Name="Growth" 
                                             Header="Growth %" 
                                             HeaderStyle="{StaticResource RightAlignedColumnHeaderStyle}"
                                             ElementStyle="{StaticResource RightAlignStyle}" Width="0.2*" >
                    <datagrid:DataGridTextColumn.Binding>
                        <MultiBinding Converter="{StaticResource GrowthConverterPercentence}">
                            <Binding Path="VolumeActual" />
                            <Binding Path="VolumeLastYear" />
                        </MultiBinding>
                    </datagrid:DataGridTextColumn.Binding>
                </datagrid:DataGridTextColumn>
                <datagrid:DataGridTextColumn x:Name="ShareVolume" 
                                             Header="Share Of Volume" 
                                             HeaderStyle="{StaticResource RightAlignedColumnHeaderStyle}"
                                             ElementStyle="{StaticResource RightAlignStyle}" Width="0.4*">
                    <datagrid:DataGridTextColumn.Binding>
                        <MultiBinding Converter="{StaticResource GrowthConverterPercentence}" >
                            <Binding Path="TotalThisYear" />
                            <Binding Path="VolumeActual" />
                            <Binding Path="TotalThisYear" />
                        </MultiBinding>
                    </datagrid:DataGridTextColumn.Binding>
                </datagrid:DataGridTextColumn>
            </datagrid:DataGrid.Columns>
        </datagrid:DataGrid>

Hi! 

 I have some issues when using the WPF Datagrid, I' am clicking on the headers and some of them are doing the sorting correctly, but other are not sorting at all. 

 I have added my code for the Datagrid 

 

 I have no problems with the fields : "This Year" and "Last Year" but my "Growth %", "Growth Liters" and "Share Of Volume" doesn't sort at all. 

 How can I get them to sort?