טוב, אז קודם כל קצת התבלבתי מקודם וכתבתי ListView אך השתמשתי ב ListBox
(listView הוא יורש מlistbox ויש לו תכונות קצת יותר מתקדמות...)
לענייננו, מה שעשיתי בסוף זה השתמשתי בExpander בשביל הרמה הראשונה, ובתוכו הכנסתי את הListView, כך שברגע שלוחצים על שם הספר נפתחת הרשימה עם כל הפרקים, וכשלוחצים על הפרק הרצוי - מוצג התוכן שלו.
הנה הקוד:
<DataTemplate x:Key="MetroDataTemplate1">
<Expander>
<Expander.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Path Data="{Binding Image}" Stretch="Uniform" Width="28" Height="28"
Fill="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}, Path=Foreground}" />
<StackPanel Grid.Column="1" Margin="5">
<TextBlock Text="{Binding Path=Title, FallbackValue=Title}" FontFamily="Segoe UI light" FontSize="14"
Foreground="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}, Path=Foreground}" />
</StackPanel>
</Grid>
</Expander.Header>
<ListView HorizontalAlignment="Left" VerticalAlignment="Top" Width="250"
Background="{x:Null}" BorderBrush="{x:Null}"
ItemsSource="{Binding Children}"
SelectionChanged="SubSideBar_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" FontFamily="Segoe UI light" FontSize="14"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Expander>
</DataTemplate>

פורסם במקור בפורום CODE613 ב02/05/2016 10:20 (+03:00)

