I have a ListView that displays sales orders, and groups them by status. In WinForms I had a footer at the bottom of each group that displayed the Total sale price for each group, and I would like to do the same in WPF.
I have figured out how to group the orders, but I can’t figure out how to create a footer.
This is my current group style:
<ListView.GroupStyle> <GroupStyle HidesIfEmpty='True'> <GroupStyle.HeaderTemplate> <DataTemplate> <!--CollectionViewGroup.Name will be assigned the value of Status for that group.--> <!--http://stackoverflow.com/questions/639809/how-do-i-group-items-in-a-wpf-listview--> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width='*' /> <ColumnDefinition Width='*' /> </Grid.ColumnDefinitions> <TextBlock Grid.Column='0' Text='{Binding Path=Name}' HorizontalAlignment='Left' FontWeight='Bold' Foreground='Black'/> <Line Grid.Column='1' Stroke='Black' X2='500' Fill='Black' VerticalAlignment='Center' /> </Grid> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ListView.GroupStyle>
If your looking for something like this:
(source: bendewey.com)
Then you can use the Template property of the ContainerStyle for the GroupStyle. In this example I use a DockPanel, with the Grid you supplied Docked on the bottom and an ItemsPresenter filling the remainder. In addition in order to get the Items totaled you’d have to use a Converter, which is supplied at the bottom.
Window.xaml
MyDataSource.cs
User.cs
TotalSumConverter.cs