gcso
gcso

Reputation: 2355

VerticalAlignment="Stretch" stretches out of my container

I have a parent container that is used to hold all of my user controls. The issue is that I use VerticalAlignment="Stretch" to stretch contents to the full height and get a vertical scroll bar the user control gets stretched too much. The vertical scrollbar appears but there is no way to scroll. I know this because the down arrow for the scroll bar isn't visible.

I have <ContentControl Content="{Binding Workspace}" /> which is where a variety of controls can be assigned. For example, here is the XAML that is not working property in regards to stretching.

<StackPanel>
    <TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" Margin="0 0 0 8" />
    <ScrollViewer VerticalAlignment="Stretch">
        <TreeView 
        ItemsSource="{Binding Listing}"
        Grid.Row="1" 
        BorderThickness="0" 
        VirtualizingStackPanel.IsVirtualizing="True" />
    </ScrollViewer>
</StackPanel>

I only want to the TreeView to stretch and display a vertical scrollbar.

Any ideas?

Upvotes: 0

Views: 1893

Answers (1)

paparazzo
paparazzo

Reputation: 45106

I suspect the height of the StackPanel is not contrained so it grows to accomodate the ScrollViewer. You can check this by putting a border on the StackPanel.

    <Border>
        <StackPanel>   
            <TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" />   
            <ScrollViewer VerticalAlignment="Stretch">   
                <TreeView ItemsSource="{Binding Listing}"  BorderThickness="0"    
                VirtualizingStackPanel.IsVirtualizing="True" />   
            </ScrollViewer>   
        </StackPanel>          
    </Border>

Upvotes: 1

Related Questions