大家好,我正在做一个通过telnet配置网络设备的项目,我使用的是C# Wpf。问题是我有一个可观察的集合,我想显示在可观察集合中的项目数,但它没有显示。我试过以下几点:
public ObservableCollection<VLANSPropertyClass> vlan { get; set; }
public int Vlans
{
// Retreive value from Configuration Library
get
{
return this.vlan.Count;
}
}XAML是:
<TextBlock Margin="3,0"
Style="{StaticResource SummaryValues}"
Text="{Binding Path=Vlans}"
Visibility="Visible"
/>现在它没有显示任何.Any帮助非常值得注意的东西:)
发布于 2014-12-08 14:15:02
最简单的方法是简单地绑定到vlan.Count (在我的示例中,我使用了textbox,但textBlock不需要OneWay)。不需要额外的属性或INotifyPropertyChanged。添加到集合将自动更新计数。
<TextBox Text="{Binding vlan.Count, Mode=OneWay}" />或
<TextBlock Text="{Binding vlan.Count}" />发布于 2014-12-08 14:00:31
绑定不知道何时更新目标。您需要实现INotifyPropertyChanged,订阅.CollectionChanged,并在Vlans (计数)更改时引发PropertyChanged事件。
发布于 2014-12-08 14:10:53
您可以在ListCollectionView之上使用ObservableCollection。
在您的ViewModel中,将它们定义为:
ObservableCollection<VLANSPropertyClass> vlan;
public System.Windows.Data.ListCollectionView CountingView { get; private set; }然后,将集合初始化为ObservableCollection:
CountingView = new System.Windows.Data.ListCollectionView(vlan);在xaml中,绑定到集合的Count属性:
<TextBlock Margin="5" Height="35" Width="50" Text="{Binding CountingView.Count}" />我希望这能帮到你!
https://stackoverflow.com/questions/27359529
复制相似问题