Im trying to achive something like here WPF DataGrid Grouping with sums and other fields to sum up 'quantity' property from items in a group. But it throws exception in foreach loop that it cant convert 'items' to my Type ('OrderItem' of which i thought items should be...)
C#
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 (OrderItem gi in items )
{
total += gi.quantity;
}
return total.ToString();
}
return "0";
}
XAML
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" Margin="5"/>
<TextBlock Text="Count" Margin="5" />
<TextBlock Text="{Binding Path=Items, Converter={StaticResource additionConverter}}" Margin="5"/>
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
and resource
<local:AdditionConverter x:Key="additionConverter" />
how to get access to the base element of 'value'? I puted a breakpoint and it is there. Sorry if i messed up something, i'm new to WPF.