I know how to Bind to Count, but how do I do it, if I only want the count where type is Product
<TextBlock Text="{Binding Items.Count}" />
Items = new ObservableCollection<object>();
I tried with a Property, But I am having problem keeping it in sync when Items are being added or removed.
public int ProductCount
{
get
{
return Items.Cast<object>().Count(item => item.GetType() == typeof (ProductViewModel));
}
}
Additional to getting the correct number of items matching the type you have to guarantee that the
PropertyChangedevent of the view model is raised when the item collection is changed. So basically what you need is something like this: