C# 嵌套数据绑定到Gridview

C# 嵌套数据绑定到Gridview,c#,xaml,gridview,binding,C#,Xaml,Gridview,Binding,我正在尝试将嵌套项数据绑定到Gridview。我对顶级项目没有问题,只有那些嵌套的主题名称我无法访问。这是我的代码目前的样子 studentSearch.xaml.cs public class StudentSearchData : INotifyPropertyChanged { private string studentName; public string StudentName { get { return studentName; }

我正在尝试将嵌套项数据绑定到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; }
}
学生搜索.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.List1[[Studies.API.StudentSearchData,Studies,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null]]上未找到“Name”属性,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=null]],mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e';目标元素是'Windows.UI.Xaml.Documents.Run'Name='null';目标属性为“文本”类型“字符串”


您的GridView正在使用ItemSource“StudentName”。尝试将其更改为StudentSearchData,在XAML上,由于Subject是一个列表,您需要通过调用Subject.Name来访问它