我正在尝试使用ObservableCollection将项目列表添加到我的Listview中。
构建时,在第2行中出现此错误:“ StudentCollection”,如下所示:
Inconsistent accessibility: property type System.Collections.ObjectModel.ObservableCollection<HMSystem.ChildPage1.studentData>' is less accessible than property 'SHSystem.ChildPage1.studentCollection' d:\data\visual studio 2010\Projects\SSSystem\SHSystem\ChildPage1.xaml.cs
到目前为止,这是我尝试过的
// created a property
private ObservableCollection<studentData> _StudentCollection;
public ObservableCollection<studentData> StudentCollection
{
get
{
if (_StudentCollection== null)
{
_StudentCollection= new ObservableCollection<studentData>();
}
return _StudentCollection;
}
}
//created a class for studentData
class studentData
{
public string StudentName{ get; set; }
public string Class{ get; set; }
public string Status { get; set; }
}
在构造函数中:
public ChildPage1()
{
_StudentCollection.Add(new studentData{ StudentName = "Arun", Class= "tenth", Status = "Active" });
_StudentCollection.Add(new studentData{ StudentName = "Priya", Class= "ninth", Status = "Active" });
InitializeComponent();
}
在XAML中:
<ListView Height="96" Name="listView1" Width="226" ItemsSource="{Binding ElementName=Page1,Path=StudentCollection}">
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="Name" DisplayMemberBinding="{Binding StudentName}" />
<GridViewColumn Width="70" Header="Class" DisplayMemberBinding="{Binding Class}" />
<GridViewColumn Width="70" Header="Status" DisplayMemberBinding="{Binding Status}" />
</GridView>
</ListView.View>
</ListView>
有任何想法吗 ??
谢谢
最佳答案
这是因为您的集合StudentCollection
是公共的,而您的类studentData
是私有的。只是公开:
public class studentData
{
public string StudentName{ get; set; }
public string Class{ get; set; }
public string Status { get; set; }
}