Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="MultiMedialab.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:MultiMedialab"
- DataContext="{Binding RelativeSource={RelativeSource Self}}"
- Title="MainWindow" Height="350" Width="525"
- Loaded="Window_Loaded">
- <Window.Resources>
- <!-- Book Chapters -->
- <DataTemplate DataType="{x:Type local:BookChapter}">
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="{Binding Path=Name}" />
- <ItemsControl ItemsSource="{Binding Path=Pages}" />
- </StackPanel>
- </DataTemplate>
- <!-- Book Pages -->
- <DataTemplate DataType="{x:Type local:BookPage}">
- <StackPanel Orientation="Horizontal" >
- <TextBlock Text="{Binding Path=Id}" Margin="5 0"/>
- <TextBlock Text="{Binding Path=Name}" Margin="5 0"/>
- <ItemsControl ItemsSource="{Binding Path=Exercises}" />
- </StackPanel>
- </DataTemplate>
- </Window.Resources>
- <Grid>
- <ListBox ItemsSource="{Binding Path=Chapters}" Name="lboxTest" />
- </Grid>
- </Window>
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- ObservableCollection<BookChapter> chapterItm = new ObservableCollection<BookChapter>();
- public ObservableCollection<BookChapter> Chapters
- { get { return chapterItm; } }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- List<string> stringcol1 = new List<string>();
- stringcol1.Add("Excercise 1");
- stringcol1.Add("Excercise 2");
- List<string> stringcol2 = new List<string>();
- stringcol2.Add("Excercise 5");
- stringcol2.Add("Excercise 6");
- List<BookPage> subList1 = new List<BookPage>();
- subList1.Add(new BookPage { Name = "Page 1 ", Id = "ID1", Excercises = stringcol1});
- subList1.Add(new BookPage { Name = "Page 2", Id = "ID2", Excercises = stringcol2 });
- List<BookPage> subList2 = new List<BookPage>();
- subList2.Add(new BookPage { Name = "Page 5", Id = "ID 21", Excercises = stringcol1 });
- subList2.Add(new BookPage { Name = "Page 6", Id = "ID22", Excercises = stringcol2 });
- chapterItm.Add(new BookChapter { Name = "Chapter 1", Pages = subList1});
- chapterItm.Add(new BookChapter { Name = "Chapter 2", Pages = subList2 });
- }
- }
- public class BookChapter
- {
- public string Name { get; set; }
- public List<BookPage> Pages { get; set; }
- }
- public class BookPage
- {
- public string Id { get; set; }
- public string Name { get; set; }
- public List<String> Excercises { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement