You can use the converter that passed the Items property of the group header, for example.
<Window.Resources> <local:GroupsToTotalConverter x:Key="groupsConverter" /> </Window.Resources> <Expander.Header> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Name}" Margin="5"/> <TextBlock Text="total" Margin="5" /> <TextBlock Text="{Binding Path=Items, Converter={StaticResource groupsConverter}}" Margin="5" /> </StackPanel>
where the converter performs the calculation and passes the final value as a string for the text block:
public class GroupsToTotalConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is ReadOnlyObservableCollection<Object>) { var items = (ReadOnlyObservableCollection<Object>)value; Decimal total = 0; foreach (GroupItem gi in items) { total += gi.Amount; } return total.ToString(); } return ""; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; } }
As for the description, I would also suggest grouping it and writing another converter to pull the description from the Elements in the same way above.
source share