ListView with nested extender not collapsing

This question is the same as this other unanswered question .

When the expander expands, the external ListView grows to make room for the contents of the expanders, but when Expander expands, the view does not resize the ListView.

Reduced code with notes after:

<!--<StackPanel>--> <ItemsControl> <!-- ParameterGroupView --> <Border BorderBrush="Brown" BorderThickness="1" CornerRadius="4" Padding="4"> <ListView HorizontalContentAlignment="Stretch"> <Expander Header="Expander A" IsExpanded="False"> <ListView HorizontalContentAlignment="Stretch"> <!-- TextView --> <TextBlock >Content A</TextBlock> <TextBlock >Content B</TextBlock> </ListView> </Expander> </ListView> </Border> </ItemsControl> <!--</StackPanel>--> 

I have a ParameterGroupView in an ItemsControl or StackPanel, because there are actually a lot of ParameterGroupView entries. Switching to a StackPanel does not change the behavior.

Removing Boarder does not affect the behavior, but it helps to show the behavior with only one GroupView parameter.

An external ListView can have many Expander sections, and an Expander can have many objects inside an internal ListView.

The external ListView and Expander should replace the TreeView, which was used to have a list of replaceable nodes, but the internal use of TreeView grids means that the TextView elements were compressed horizontally, just as if you removed the ether HorizontalContentAlignment = "Stretch" attributes.

So, if there is another way to wrap it all up, I will be happy too.

This is a problem because our TextView blocks are large and there are many expanders.

Edit: TextView is used because the code is data bound and therefore dynamically merged. Therefore, for any ListView replacement, some form of ItemsSource is required.

+7
listview wpf expander
source share
2 answers

Found a solution, and he details where in the question already.

ItemControl accepts the ItemsSource and auto parameters. Thus, replacing two ListViews with ItemControls results in a nested attachment.

But there is no scrolling, so wrapping the external ItemControl with ScrollViewer reproduces the full desired effect.

 <ScrollViewer VerticalScrollBarVisibility="Auto"> <ItemsControl> <!-- ParameterGroupView --> <Border BorderBrush="Brown" BorderThickness="1" CornerRadius="4" Padding="4" Height="Auto"> <ItemsControl HorizontalContentAlignment="Stretch"> <Expander Header="Expander A" IsExpanded="False"> <ItemsControl HorizontalContentAlignment="Stretch"> <!-- TextView --> <TextBlock>Content A</TextBlock> <TextBlock>Content B</TextBlock> </ItemsControl> </Expander> </ItemsControl> </Border> </ItemsControl> </ScrollViewer> 

I tested dual expanders in border and dual-border partitions.

+4
source share

The most obvious thing to do is put the expanders in a container other than the list:

 <Border BorderBrush="Brown" BorderThickness="1" CornerRadius="4" Padding="4"> <StackPanel> <Expander Header="Expander A" IsExpanded="False"> <ListView HorizontalContentAlignment="Stretch" MinWidth="100"> <ListBox Name="listb"></ListBox> <!-- TextView --> <TextBlock >Content A</TextBlock> <TextBlock>Content B</TextBlock> </ListView> </Expander> </StackPanel> </Border> 

A container can very easily resize content.

If you absolutely must have it in a ListView (which is possible), then I don’t know how to get a ListView to easily resize as soon as it grows (except for setting explicit sizes for everything that is inconvenient and not useful). If so, then you may need to use a managed list to display all open expanders or display content in a different way (for example, a popup, maybe?), If you want to see it all at a glance.

+2
source share

All Articles