gpt4 book ai didi

wpf - 如何从 XAML 获取 ObservableCollection 中的项目数?

转载 作者:行者123 更新时间:2023-12-04 10:02:32 24 4
gpt4 key购买 nike

我正在显示我从 ComboBox 中的 ViewModel ObservableCollectoin 属性获得的所有客户,如下所示:

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

有没有办法获取 ObservableCollection 中的项目数无需创建另一个 ViewModel 属性 ,例如像这样:

伪代码:
<TextBlock Text="{Binding Customers.Count()}"/>

最佳答案

ObservableCollection 类型公开了一个您可以使用的 Count 属性。
我不知道 ObservableCollection 是否会引发 PropertyChanged 事件以通知 UI 有关此属性的更新。

关于wpf - 如何从 XAML 获取 ObservableCollection 中的项目数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1012471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com