WPF - scroll list in expander

I have an Expander in which I want to have a ListBox . When I open Expander , the ListBox simply expands the screen (instead of expanding to fill in what is available, and then scrolling).

Here is my XAML:

 <DockPanel Margin="266.25,0,455,12" Name="dockPanel1"> <StackPanel> <Expander Header="expander1" Name="expander1" Width="150" HorizontalAlignment="Left"> <Grid> <Label>Testing</Label> <ScrollViewer> <ListBox Name="lstBox" FontSize="14" SelectionChanged="lstBox_SelectionChanged" /> </ScrollViewer> </Grid> </Expander> <Expander Header="expander2" Name="expander2" Width="150" HorizontalAlignment="Left"> <Grid > </Grid> </Expander> </StackPanel> </DockPanel> 

When Expander1 opens, it simply expands to the size of the ListBox (from the screen). If I put the size in the grid ( Height="275" ), it will not resize using the window.

I want it to stretch to the size of the window, but nothing more. Is there any way to do this?

+4
source share
1 answer

You need to set the Height property for the ScrollViewer, otherwise it will be the same size as the child. Here are some updated versions of XAML:

 <DockPanel> <StackPanel> <Expander Header="expander1" Width="150" HorizontalAlignment="Left"> <StackPanel> <Label>Testing</Label> <ScrollViewer Height="75"> <ListBox> </ListBox> </ScrollViewer> </StackPanel> </Expander> <Expander Header="expander2"> </Expander> </StackPanel> </DockPanel> 
+2
source

All Articles