为了简化我的问题,假设我有一个属性,我将我的DataGrid绑定到该属性上:
现在我如何绑定属性Library,以便在DataGrid中获得所有书籍的列表:
public List<LibrarySection> Library { get; set; }
然后每个LibrarySection中我都有:
class LibrarySection
{
public string SectionName{ get; set; }
public List<Book> Books { get; set; }
}
这是一本书的样子:
class Book
{
public string Name { get; set; }
public string Author { get; set; }
public string BookID { get; set; }
}
现在我如何绑定属性Library,以便在DataGrid中获得所有书籍的列表:
![Book table](https://istack.dev59.com/kUtqS.webp)
LiblarySection
,而是一个名为 Library 的 List<LibrarySection>,正如我在问题中所述。此外,我同意应该使用ObservableCollection<T>
,但这不由我决定。 - karollo{Binding Library[0].Books}
绑定单个库 - 或者为每个库创建一个新的DataGrid
。从 WPF www.wpf-tutorial.com 和/或 www.wpftutorial.net 开始可能会非常有帮助。这些网站上有很多使用DataGrid
的示例。对于您的情况,分组
也可能很有趣! - Felix D.