9

I'm displaying all of my customers which I get from a ViewModel ObservableCollectoin property within a ComboBox like this:

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

Is there a way to get the number of items in the ObservableCollection without creating another ViewModel property, e.g. something like this:

PSEUDO-CODE:

<TextBlock Text="{Binding Customers.Count()}"/>
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047

1 Answers1

18

The ObservableCollection type exposes a Count Property which you can use. I don't know if ObservableCollection raises the PropertyChanged event in order to inform the UI about updates to this property though.

wonea
  • 4,783
  • 17
  • 86
  • 139
Joachim Kerschbaumer
  • 9,695
  • 7
  • 49
  • 84