2009-06-18 21 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

相關問題