Prevent WPF control from expanding beyond viewable area
- by Dan dot net
I have an Items Control in my user control with a scroll viewer around it for when it gets too big (Too big being content is larger than the viewable area of the user control). The problem is that the grid that it is all in just keeps expanding so that the scroll viewer never kicks in (unless I specify an exact height for the grid). See code below and thanks in advance.
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="300px">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GroupBox FontWeight="Bold"
Header="Tables"
Padding="2">
<ScrollViewer>
<ItemsControl FontWeight="Normal" ItemsSource="{Binding Path=AvailableTables}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Path=DisplayName}"
IsChecked="{Binding Path=IsSelected}"
Margin="2,3.5" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</GroupBox>
</Grid>
I would like to not specify the height.