垂直拉伸WebBrowser以适应内容

时间:2012-09-12 19:18:12

标签: windows-phone-7 xaml

当我有一个WebBrowser控件时,我的页面布局出现了一些问题。

这是我的XAML的重要部分:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,12">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="{Binding Title}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <StackPanel Grid.Row="1" Margin="12,17,0,12">
        <phone:WebBrowser Name="HtmlBody" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Red" Margin="12,17,0,28"/>
    </StackPanel>
</Grid>

我的问题是如何让WebBrowser成为一个好的选择。将其属性设置为auto无济于事。如果我这样做,则默认为0。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

使用Grid而不是StackPanel,并将第二行的高度设置为“*”,如下所示:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,12">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="{Binding Title}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid Grid.Row="1" Margin="12,17,0,12">
        <phone:WebBrowser Name="HtmlBody" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Red" Margin="12,17,0,28"/>
    </Grid>
</Grid>