【发布时间】:2011-12-02 23:20:06
【问题描述】:
我知道如何绑定到计数,但是如果我只想要类型为 Product 的计数,我该怎么做
<TextBlock Text="{Binding Items.Count}" />
Items = new ObservableCollection<object>();
我尝试使用属性,但在添加或删除项目时无法保持同步。
public int ProductCount
{
get
{
return Items.Cast<object>().Count(item => item.GetType() == typeof (ProductViewModel));
}
}
【问题讨论】:
-
您是否尝试过使用 LINQ TypeOf
扩展方法?
标签: c# wpf binding inotifypropertychanged