how do i binding itemcount to my datacontext to count all the items in each of my groups and then show it in the header
Mærke is the PropertyGroupDescription
where my items are binding to
view model
string Data =
@"Select ps.Mærket AS Mærke, P.DataID, P.Billed, P.Model,
P.Årgang, P.[Motor Type], P.Krydsmål, P.Centerhul,
P.ET,P.Bolter, P.Dæk, P.Fælge ,PS.Krydsmålene
from Data.Hjuldata P
inner join Data.Mærke PS on P.MærkeID = PS.MærkeID
ORDER BY ps.Mærket";
ICollectionView dataView = CollectionViewSource.GetDefaultView(hjuldata.ItemsSource);
dataView.GroupDescriptions.Add(new PropertyGroupDescription("Mærke"));
data context
<Expander.Header>
<StackPanel Orientation="Horizontal" DataContext="{Binding Items}">
<Image Source="{Binding Billed}" Width="20" Height="20" Stretch="Fill" VerticalAlignment="Center" Margin="0,0,15,0"/>
<TextBlock Text="{Binding Mærke}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding Krydsmålene}" FontWeight="Bold" Foreground="#FFFBFB00" FontSize="22" VerticalAlignment="Bottom" Margin="0,0,150,0" TextAlignment="Center" />
</StackPanel>
</Expander.Header>
it worked before with this
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22 "VerticalAlignment="Bottom"/>
</StackPanel>
</Expander.Header>
System.Windows.Data Error: 4 : Cannot find source for binding with reference
'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''.
BindingExpression:Path=ItemCount; DataItem=null;
target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')