无法让我的列表视图显示数据。ListView Observable Collection不会显示成员
XAML
<Grid>
<DockPanel>
<ListView Name="lstDetectedComputers"
MinWidth="200"
DockPanel.Dock="Left"
ItemsSource="{Binding ComputersList}" DisplayMemberPath="ComputerName">
</ListView>
<DataGrid x:Name="ViewNetworkCardInformation"
ItemsSource="{Binding NetworkCardInformation}"/>
</DockPanel>
</Grid>
代码:
private ObservableCollection<Object> _ComputersList;
public ObservableCollection<Object> ComputersList
{
get
{
return _ComputersList;
}
set
{
_ComputersList = value; NotifyPropertyChanged("ComputersList");
}
}
private DataTable _NetworkCardInformation;
public DataTable NetworkCardInformation
{
get
{
return _NetworkCardInformation;
}
set
{
_NetworkCardInformation = value; NotifyPropertyChanged("NetworkCardInformation");
}
}
奇怪的是,NetworkCardInformation显示在数据网格我所以这表明在DataContext工作正常。
现在im用ObservableCollection的印象我不需要INotifyPropertyChange,如果这是错误的,请建议。
我也有尝试过的ItemsSource =“{结合ComputersList}”
我已经把一个破发点入代码,以确保观察集合有数据,而且它的存在。
- ComputersList计数= 2 System.Collections.ObjectModel.ObservableCollection
- [0] {AdminUltimate.Model.NetworkModel.ComputerNode} {对象} AdminUltimate.Model.NetworkModel.ComputerNode计算机名 “华硕-PC” 串
有人请协助。 谢谢
错误的印象。 ObservableCollection实现INotifyCollectionChanged(而不是INotifyPropertyChanged)。 OC通知插入和删除 - 不改变现有项目。 – Paparazzi
尝试将'ComputersList'属性声明为'ObservableCollection'而不是'ObservableCollection
同意har07。 NotifyPropertyChanged( “ComputersList”);不属于那里。 ComputerNode需要一个NotifyPropertyChanged(“ComputerName”); – Paparazzi