【问题标题】:How to do data-binding with child-objects?如何与子对象进行数据绑定?
【发布时间】:2014-02-04 13:23:02
【问题描述】:

我有三个类,如下所示:

父类:

public class Artist
{
    public string name { get; set; }
    public List<Album> Albums { get; set; }
    public string Biography { get; set; }
}

中产阶级:

public class Album
{
    public string name { get; set; }
    public int year { get; set; }
    public List<Artist> artists { get; set; }
    public List<Track> Tracks { get; set; }
}

还有子类:

public class Track
{
    public string name { get; set; }
    public int year { get; set; }
    public Int64 duration { get; set; }
    public List<string> genre { get; set; }
    public string searchpath { get; set; }
    public Album album { get; set; }

}

如您所见,Artist 对象有一个专辑列表,而 Album 对象有一个曲目列表。

如果我有一个曲目列表(其中引用了它的父母),如果我想要一些带有艺术家姓名、专辑名称和曲目标题的文本块,我将如何将它与 Listview 绑定?

有没有办法在绑定中做{Binding Path=track.album.name}

【问题讨论】:

  • Is there any way to do {Binding Path=track.album.name} in the binding? 。您在发布此问题之前尝试过吗?
  • 我做到了,是的。当我尝试它时遇到了一些异常,认为是因为这个。必须多看一下我的代码.. 抱歉

标签: c# wpf xaml data-binding


【解决方案1】:

是的。如果您的 DataContext 设置为 Track 对象,您可以使用路径“album.name”来绑定曲目的专辑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多