The main application window is divided into grids, one of which is a ListView for selecting content (Page) in the other. ListViewItem, which is just in ListView, you can hover and select, while loading the page I need (PageClient.xaml). But it is impossible to select ListViewItem from Expander, just point it, so I cannot load PageCategory.xaml. Please tell me how to solve this problem.

<StackPanel HorizontalAlignment="Left" Grid.Row="1" Grid.ColumnSpan="2" Margin="0 0 0 0" Background="#06061d" > <ListView x:Name="GridMenu" Foreground="White" FontFamily="Champagne &amp; Limousines" FontSize="18"> <ListViewItem Height="50" Margin="0,5,0,0" Padding="0" ScrollViewer.CanContentScroll="True"> <ListViewItem.Tag> <Frame Name="frame2" Margin="0,0,0,0" Source="PageClient.xaml" /> </ListViewItem.Tag> <StackPanel Orientation="Horizontal" Margin="10 0"> <materialDesign:PackIcon Kind="Account" Width="20" Height="20" Foreground="#FFF08033" Margin="5" VerticalAlignment="Center"/> <TextBlock Text="Клиенты" Margin="10"/> </StackPanel> </ListViewItem> <Expander Background="#06061d" MinHeight="40" Width="264"> <Expander.Header> <StackPanel Orientation="Horizontal" Margin="-20,0,0,0"> <materialDesign:PackIcon Kind="Information" Width="20" Height="20" Foreground="WhiteSmoke" Margin="5" VerticalAlignment="Center"/> <TextBlock Foreground="White" Margin="10 0 0 0" Text="Справочники" Height="20"></TextBlock> </StackPanel> </Expander.Header> <StackPanel Background="#06061d" > <ListViewItem Height="40" Padding="0"> <ListViewItem.Tag> <Frame Name="frame3" Margin="0,0,0,0" Source="PageCategory.xaml" /> </ListViewItem.Tag> <StackPanel Orientation="Horizontal" Margin="34 0"> <TextBlock Text="Категории" Margin="10"/> </StackPanel> </ListViewItem> </Expander> </ListView> </StackPanel> <Border Grid.Column="1" Grid.Row="1" BorderThickness="0" Margin="0,0,0,0"> <ContentControl Content="{Binding SelectedItem.Tag, ElementName=GridMenu, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,0,0"/> </Border> </Grid> 
  • If you need a hierarchical structure, use TreeView. And keep in mind that all items that are not a ListViewItem will be wrapped in it, i.e. your Expander will be inside the ListViewItem , select accordingly, you can only make this external ListViewItem current and push ListViewItem somewhere deeper just does not make sense. Well, in general, your approach is different from the conventional and irrational. Read about DataTemplate and use it. - Andrey NOP
  • Thanks for the advice, just completely rewriting the beautiful menu shell under the TreeView has no time. - Blue Jeans

1 answer 1

The problem was solved by creating several ListViews instead of one and redefining the ContentControl content in the code by setting the ListViewItem_Selected event for each item.