我想建立这样一个的UserInterface(用于视频编辑时间轴) C#数据绑定嵌套的ItemsControl WPF
,我有所有的类:
public class Timeline
{
public Timeline()
{
groups = new ObservableCollection<Group>();
}
public ObservableCollection<Group> groups { get; set; }
}
public class Group
{
public string Name { get; set; }
public TrackGroup()
{
tracks = new List<Track>();
}
public List<Track> tracks { get; set; }
}
public class Track
{
public Track()
{
units= new ObservableCollection<Unit>();
}
public ObservableCollection<Unit> units { get; set; }
}
public class Unit
{
public string unitName { get; set; }
}
而且在主要我有这:
public Timeline timeline = new Timeline();
public Unit unit = new Unit();
public Track track = new Track();
public Group group = new Group();
track.units.Add(unit);
group.tracks.Add(track);
timeline.groups.Add(group);
而且在Main.xaml(不完整的,因为它不工作)
<ListBox
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding timeline.groups}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel LastChildFill="True">
<ItemsControl ItemsSource="{Binding timeline.groups.tracks}">
<ItemsControl.ItemTemplate >
<ItemsControl ItemsSource="{Binding timeline.groups.tracks.units}">
<ItemsControl.ItemTemplate >
</ItemsControl.ItemTemplate >
</ItemsControl>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如何绑定每个itemssource?因为时间轴,组,轨道所有列表,所以我需要在ItemsControl中显示它们。我很困惑
它不适用于“绑定timeline.groups”。我在主类中使用“datacontext = this”,是不是? –
已更新的答案。 – Shakra