垂直拉伸 WebBrowser 以适应内容
问题描述:
当我有一个 WebBrowser 控件时,我在页面布局方面遇到了一些问题.
I've been having some issues with the layout of a page when I have a WebBrowser control in it.
这是我的 XAML 的重要部分:
Here's the significant portion of my 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.
My question is how do I make the WebBrowser streatch. Setting it's properties to auto doesn't help. If I do that it defaults to a height of 0.
有什么想法吗?
答
使用 Grid 而不是 StackPanel,并将第二行的高度设置为*",如下所示:
Use Grid instead of the StackPanel, and set the height of the second row to "*", like this:
<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>