Question

I have a DataGrid in a Silverlight 5 application that contains a column with percent values. I display the data with progress bars. When I click on the column header I want the DataGrid content to be sorted by the percent values. How can I do that?

Example: These 3 progress bars

=========
======
===========

should be like this after sorting:

===========
=========
======

I define the DataGrid like this:

<sdk:DataGrid x:Name="MainGrid"
              AutoGenerateColumns="False" ItemsSource="{Binding}">
    <sdk:DataGrid.Columns>
        <sdk:DataGridTemplateColumn Header="Übereinstimmung"
                                    Width="200" IsReadOnly="True">
            <sdk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ProgressBar
                        Width="200"
                        Padding="3"
                        IsIndeterminate="False"
                        Minimum="0"
                        Maximum="100"
                        Value="{Binding MatchingPercent}"
                        Foreground="ForestGreen"/>
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellTemplate>
        </sdk:DataGridTemplateColumn>
    </sdk:DataGrid.Columns>
</sdk:DataGrid>
Was it helpful?

Solution

Setting the SortMemberPath to the property holding the percentage values should do the trick:

<sdk:DataGridTemplateColumn
    Header="Übereinstimmung"
    Width="200"
    IsReadOnly="True"
    SortMemberPath="MatchingPercent">
    ...
</sdk:DataGridTemplateColumn>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top