2009-06-18 80 views
6

我显示了所有我的顾客,我从一个ViewModel ObservableCollectoin财产得到一个ComboBox内像这样的:如何从XAML获取ObservableCollection中的项目数量?

<ComboBox 
    ItemsSource="{Binding Customers}" 
    ItemTemplate="{StaticResource CustomerComboBoxTemplate}" 
    Margin="20" 
    HorizontalAlignment="Left" 
    SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"/> 

有没有办法让在的ObservableCollection 项目的数量,而不创建其他视图模型属性,例如是这样的:

伪代码:

<TextBlock Text="{Binding Customers.Count()}"/> 

回答

16

的的ObservableCollection类型公开,你可以用一个Count属性。 我不知道是否ObservableCollection引发PropertyChanged事件,以便通知UI关于此属性的更新。

+4

确定它只是这样的:,并且它似乎在ObservableCollection更改时不断更新,很好。 – 2009-06-18 13:02:12

相关问题