我想建立這樣一個的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