开发者

Formatting ScrollView to occupy the parent container

开发者 https://www.devze.com 2023-04-08 22:36 出处:网络
I am trying to format the scroll view to completely occupy the parent container, but it looks like I\'m missing something. Any suggestions would be great.

I am trying to format the scroll view to completely occupy the parent container, but it looks like I'm missing something. Any suggestions would be great.

XAML:

<Border Grid.Row="0" BorderBrush="#1B5468" BorderThickness="3,3,3,3" CornerRadius="7,7,7,7" Margin="5,0,5,5">
    <StackPanel Height="Auto" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <StackPanel HorizontalAlignment="Center" Width="350" Height="30">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <Image Source="..开发者_StackOverflow/Images/Blue.png" Stretch="Fill" Margin="7,0,5,-27" Height="52" />
                <TextBlock HorizontalAlignment="Center" Height="Auto"  Margin="36,3,-2,4" Name="lblHeader" Text="Comments" VerticalAlignment="Center" Width="Auto" Foreground="Silver" FontWeight="Bold" FontSize="12" />
            </Grid>
        </StackPanel>
        <ScrollViewer Height="Auto" HorizontalAlignment="Stretch" Name="dComments_Scroll" VerticalAlignment="Stretch" Width="Auto" HorizontalContentAlignment="Left" VerticalContentAlignment="Top">

            <StackPanel Height="Auto" Name="dStack_Comments" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False">
            </StackPanel>
        </ScrollViewer>
    </StackPanel>
</Border>

Formatting ScrollView to occupy the parent container


By putting your ScrollViewer in a StackPanel, you're saying "make this ScrollViewer just tall enough to hold its content". That's what StackPanel is designed to do -- to make each child exactly as tall as it needs to be to show all its content, and then stack the next child right underneath. If that's not the layout you want, don't use a StackPanel.

Edit: Instead of a StackPanel inside your Border, you probably want a Grid. (I originally wrote DockPanel, forgetting that Silverlight doesn't ship with a DockPanel.) Grid is flexible enough to let you have some controls autosized, and other controls filling (or sharing) the remainder of the available space.

<Border ...>
    <Grid ...>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" ...>
            ...
        </StackPanel>
        <ScrollViewer Grid.Row="1" ...>
            ...
        </ScrollViewer>
    </Grid>
</Border>

Also, once you get it working, I'd strongly suggest that you see if you can simplify your XAML. You're setting a lot of properties to their default values (e.g. HorizontalAlignment="Stretch", Height="Auto"), which just makes your XAML harder to read and maintain. If you can start to learn which attributes you can remove and still keep the same behavior, you'll have a much better handle on XAML development.

0

精彩评论

暂无评论...
验证码 换一张
取 消