我有一个三个嵌套类,节目、季节和剧集,其中一个节目有季节,而季节有剧集。
我想绑定两个列表框,以便第一个列出季节,第二个列出该季节的剧集。
我怎样才能做到这一点?我更喜欢在代码中而不是 xaml 中进行设置,但如果您知道如何使用 xaml 进行设置,总比没有好。
一个简化的 xaml:
<Window>
<Label name="Showname" />
<ListBox name="Seasons" />
<ListBox name="Episodes" />
</Window>
和一些相关代码:
public partial class Window1 : Window
{
public Data.Show show { get; set; }
public Window1()
{
this.DataContex = show;
//Bind shows name to label
Binding bindName = new Binding("Name");
ShowName.SetBinding(Label.ContentProperty, bindName);
//Bind shows seasons to first listbox
Binding bindSeasons = new Binding("Seasons");
Seasons.SetBinding(ListBox.ItemsSourceProperty, bindSeasons);
Seasons.DisplayMemberPath = "SeasonNumber";
Seasons.IsSyncronizedWithCurrentItem = true;
//Bind current seasons episodes to second listbox
Binding bindEpisodes = new Binding("?????");
Episodes.SetBinding(ListBox.ItemsSourceProperty, bindEpisodes);
Episodes.DisplayMemberPath = "EpisodeTitle";
}
}
有人知道如何绑定第二个列表框吗?