I am working an a sortable WPF ListView and I made a lot of progress already. It’s not so hard since there is a lot of stuff on the internet already. But there is a little bit of information I am still missing.
With a Column like that:
<GridViewColumn Width="200" Header="Fahrzeugname" DisplayMemberBinding="{Binding Name}">
I can sort it like this:
Binding columnBinding = column.DisplayMemberBinding as Binding;
if (columnBinding != null)
{
sorts.Clear();
sorts.Add(new SortDescription(columnBinding.Path.Path, direction));
lastColumnSorted = column;
}
But my problem is I don’t have a DisplayMemberBinding since I use a DataTemplate:
<DataTemplate>
<TextBlock Text="{Binding Name}" TextAlignment="Left"/>
</DataTemplate>
How do I get the Binding property for this column in the C# Code?
I wrote a set of attached properties to do exactly what Kent suggested, you can check it out here
EDIT : as requested, here’s a sample of a command for
GridViewSort.Command:(it actually implements the same behavior as when
GridViewSort.AutoSortis set to true…)