DataGridColumn SortMemberPath on MultiBinding

I am trying to sort columns by numeric content. A multi-link converter works fine. This solution will set SortMemberPath to null

I tried various ways, and substantially washed the Internet.

The code has been changed from the original for security reasons.

<DataGridTemplateColumn x:Name="avgPriceColumn">
<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <TextBlock>
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource avgPriceConverter}">
                    <Binding Path="NumberToDivideBy" />
                    <Binding Path="TotalDollars" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.SortMemberPath>
    <MultiBinding Converter="{StaticResource avgPriceConverter}">
        <Binding Path="NumberToDivideBy" />
        <Binding Path="TotalDollars" />
    </MultiBinding>
</DataGridTemplateColumn.SortMemberPath>
</DataGridTemplateColumn>

EDIT: I found a way to get data binding to work without multitasking, but sorting still doesn't work. Since the DataGrid is bound to a custom class, I take an integer value and convert it, thereby reducing the need for MultiBinding.

<DataGridTextColumn x:Name="avgPriceColumn" Binding="{Binding Converter={StaticResource avgPriceConverter}}" SortMemberPath="{Binding Converter={StaticResource avgPriceConverter}}" />

In both of these parameters, SortMemberPath defaults to Binding, so I don’t need to explicitly define it, since I have

, SortMemberPath null, , , . .

EDIT:

, SortMemberPath,

+5
1

SortMemberPath (, "TotalDollars" ), . , , . , 15, SortMemberPath .

, :

  • (, " " ) . .

    public double AveragePrice
    {
        get { return TotalDollars / NumberToDivideBy; }
    }
    
  • OnSorting , question.

, .:)

+6

All Articles