0

当我有一个 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 streatch。将其属性设置为 auto 无济于事。如果我这样做,它默认高度为 0。

有任何想法吗?

4

1 回答 1

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>
于 2012-09-13T08:32:23.983 回答