如何通过MultiConverter输出对WPF ListView列进行排序

时间:2019-06-24 15:26:07

标签: c# wpf listview converters columnsorting

我想通过MultiConverter输出对ListView列进行排序 我正在使用ListView及其GridViewColumns来显示来自绑定的数据。

一个处理程序“ SortClickUniversal()”已添加到ListView,它依次调用“ Sort()”

如果“ Sort()”在其上方找到GridViewColumnHeader的Content String,则通过绑定元素(“ WartVPreis”)创建SortDescription,并将其添加到ListView ItemSource的默认视图中。

这对于简单的绑定(“ WartVPreis”)很好。但是我还有一个由Multibinding Converter填充的列:

<GridViewColumn Width="110" >
    <GridViewColumn.Header>
        <GridViewColumnHeader Content="WV Aktuell Netto €" 
    </GridViewColumnHeader>
    </GridViewColumn.Header>
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock 
                Text="{Binding WartVPreis, ConverterCulture=de-DE, StringFormat={}{0:F2}}"  
                HorizontalAlignment="Right" 
                />
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

C#

private void SortClickUniversal(object sender, RoutedEventArgs e)
{
        //...
        var sortBy = (e.OriginalSource as GridViewColumnHeader).Content.ToString();
        bool sortieren = Sort(sortBy, direction, sender);
        //...
}



private bool Sort(string sortBy, ListSortDirection direction, object sender)
{
    switch (sortBy)
    {
        //...
        case "WV Aktuell Netto €": sortBy = "WartVPreis"; break;
        //...
        SortDescription sd = new SortDescription(sortBy, direction);
        dataView.SortDescriptions.Add(sd);
    }
}

XAML

<GridViewColumn Width="90" >
    <GridViewColumn.Header>
        <GridViewColumnHeader Content="WV Ant. Net €"></GridViewColumnHeader>
    </GridViewColumn.Header>
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock HorizontalAlignment="Right" >
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource MultiWVAnteilConverterKey}" ConverterCulture="de-DE" StringFormat="{}{0:F2}">
                        <Binding Path="WartVPreis" />
                        <Binding Path="Dtvon" />
                        <Binding Path="Dtbis" />
                        <Binding Path="WartVZyklus" />
                        <Binding Path="WartVBJVON" />
                        <Binding Path="WartVBJBIS" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

如何通过具有MultiBinding的MultiConverter输出对列进行排序?

0 个答案:

没有答案