【发布时间】:2015-11-25 08:49:34
【问题描述】:
我正在尝试将嵌套项数据绑定到我的 Gridview。我对顶级项目没有任何问题,只有那些嵌套的(主题名称)我无法访问它。这是我的代码目前的样子。
studentSearch.xaml.cs
public class StudentSearchData : INotifyPropertyChanged
{
private string studentName;
public string StudentName
{
get
{
return studentName;
}
set
{
if (studentName != value)
{
studentName = value;
OnNotifyPropertyChanged("StudentName");
}
}
}
public List<Subject> Subjects { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void OnNotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public class Subject
{
public string Name { get; set; }
}
studentSearch.Xaml
<GridView Name="studentGridView" ItemSource="{Binding StudentName">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<DataTemplate>
<TextBlock Text="{Binding studentName}" Grid.Row="0">
<StackPanel Grid.Row="1">
<TextBlock Text="{Binding Name}" Grid.Row="0">
</StackPanel>
</DataTemplate>
</GridView>
我在尝试访问主题名称时收到的错误消息是这样的
错误:BindingExpression 路径错误:在“System.Collections.Generic.List
1[[Studies.API.StudentSearchData , Studies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. BindingExpression: Path='Name' DataItem='System.Collections.Generic.List1[[Studies.API.StudentSearchData, Name, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 上找不到“Name”属性空]],mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e';目标元素是 'Windows.UI.Xaml.Documents.Run' (Name='null');目标属性是“文本”(类型“字符串”)
【问题讨论】: