views:

11

answers:

1

I have a grid that hosts a stackpanel that hosts a listbox. The Listbox once filled from the itemssource is stretching out of the visible area of the stackpanel. I have tried limiting the grid and stackpanel in size and the listbox continues to stretch out of the visible range (it just goes to edge and continues as if nothing was there to stop it instead of limiting it's size and bringing up a vertical scrollbar). The only thing that seems to help is setting the MaxHeight on the listbox, the issue is I can't tell what that height should be for different clients. I have tried different VerticalAlignments and I have the bottom margin set to 5 to try and get it to stop at the edge but nothing has had an effect yet.

Snip: Edit to add full hierarchy:

<UserControl>
    <Grid x:Name="LayoutRoot" Background="White" Margin="0,0,0,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="230"/>
            <ColumnDefinition d:DesignWidth="500"/>
            <ColumnDefinition MinWidth="300" />
        </Grid.ColumnDefinitions>
    <StackPanel x:Name="ContentHolder" Grid.Column="0" DataContext="{Binding}" VerticalAlignment="Top">
                <ListBox Name="lst" ItemsSource="{Binding}" Margin="5,0,15,5" VerticalAlignment="Stretch">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Name}" />
                                <TextBlock Text="{Binding Number}" Margin="15,0,0,0" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
    </grid>
</usercontrol>

I have removed most of the names and such from the code to just use this as an example.

A: 

Answering this for anyone confused and looking for an answer in the future. Basically stackpanels step to a vertical orientation do not limit the size of their child controls vertically so anything with a scroll bar (datagrid, listbox, etc) probably shouldn't be used with them.

Mark