7

次のように、ComboBox 内の ViewModel ObservableCollectoin プロパティから取得したすべての顧客を表示しています。

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

別の ViewModel プロパティを作成せずに、ObservableCollection 内のアイテムの数を取得する方法はありますか。たとえば、次のようなものです。

疑似コード:

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

1 に答える 1

17

ObservableCollection タイプは、使用できる Count プロパティを公開します。ただし、このプロパティの更新について UI に通知するために、ObservableCollection が PropertyChanged イベントを発生させるかどうかはわかりません。

于 2009-06-18T12:54:24.537 に答える