How to get number of items in ObservableCollection from XAML?
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.
Angry Dan
web/software developer, .NET, C#, WPF, PHP, software trainer, English teacher, have philosophy degree, love languages, run marathons my tweets: http://www.twitter.com/edward_tanguay my runs: http://www.tanguay.info/run my code: http://www.tanguay.info/web my publications: PHP 5.3 training video (8 hours, video2brain) my projects: http://www.tanguay.info
Updated on July 06, 2022Comments
-
Angry Dan almost 2 years
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()}"/>
-
Angry Dan almost 15 yearsok it's just this: <TextBlock Text="{Binding Customers.Count}"/>, and yes it seems to constantly update when the ObservableCollection changes, nice.