Prevent WPF control from expanding beyond viewable area

Posted by Dan dot net on Stack Overflow See other posts from Stack Overflow or by Dan dot net
Published on 2010-12-23T18:40:53Z Indexed on 2010/12/23 21:53 UTC
Read the original article Hit count: 169

Filed under:

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.

© Stack Overflow or respective owner

Related posts about wpf