I have a grid:
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
The second row is with scrollviewer:
<ScrollViewer VerticalScrollBarVisibility="Auto" MinHeight="400" Grid.Row="1">
<ItemsControl ItemsSource="{Binding SelectedUserControls}"/>
</ScrollViewer>
I want the second row to be with scroll if needed, But the scroll is never visible, event if the items controls are bigger than the screen.
How can i get the scroll to appear when needed?
EDIT:
Try removing 'MinHeight=400' and I bet it works!!
You have a MinHeight on your ItemsControl of 400. So until you have enough items to take up all 400, you will not see your scrollbar. I'm guessing the container holding your grid (or the explicit height on your grid is less that 400), and you have enough items to be too big for that container, but not enough items to fill the MinHeight of your ItemsControl.
Original Answer: I just ran a test app with 30 items in it (enough to fill the MinHeight) and it seems to work fine:
<Window x:Class="TestApp11.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:TestApp11"
Title="Window1" Loaded="Window_Loaded" Height="600" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" MinHeight="400" Grid.Row="1">
<ItemsControl>
...
<ListBoxItem Content="Item 30" />
...
</ItemsControl>
</ScrollViewer>
</Grid>
</Window>
Does your container holding your grid have an explicit Height?
Change MinHeight to MaxHeight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With