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()}"/>
An ObservableCollection is a dynamic collection of objects of a given type. Objects can be added, removed or be updated with an automatic notification of actions. When an object is added to or removed from an observable collection, the UI is automatically updated.
Represents a dynamic data collection that provides notifications when items get added or removed, or when the whole list is refreshed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With