tags:

views:

276

answers:

1

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()}"/>
+2  A: 

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.

Joachim Kerschbaumer
ok it's just this: <TextBlock Text="{Binding Customers.Count}"/>, and yes it seems to constantly update when the ObservableCollection changes, nice.
Edward Tanguay