如何从 XAML 获取 ObservableCollection 中的项目数量?
我正在显示从 ComboBox 中的 ViewModel ObservableCollectoin 属性获得的所有客户,如下所示:
<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 create another ViewModel property,eg some像这样:
伪代码:
<TextBlock Text="{Binding Customers.Count()}"/>
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()}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ObservableCollection 类型公开了一个可供您使用的 Count 属性。
我不知道 ObservableCollection 是否引发 PropertyChanged 事件以便通知 UI 有关此属性的更新。
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.