我正在尝试使用 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>
有任何想法吗 ??谢谢