Ich möchte ein Userinterface wie folgt aus (ein Zeitplan für einen Video-Editor) C# Datenbindung verschachtelte Items wpf
und ich alle Klassen bauen:
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; }
}
Und in Haupt Ich habe diese :
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);
Und in Main.xaml (nicht vollständig, weil es nicht funktioniert)
<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>
Wie kann ich jede Itemquelle binden? weil timeline, gruppe, spur alle sind liste, also muss ich sie in ItemsControl zeigen. Ich war sehr verwirrt
Es funktioniert nicht von "binding timeline.groups". Ich benutze "datacontext = this" in der Hauptklasse, richtig? –
Aktualisierte Antwort. – Shakra