Web浏览器控件是不是显示整个页面?

时间:2012-02-28 11:18:26

标签: c# windows-phone-7 browser

我想知道为什么第一次尝试使用WebBrowser加载信息时,页面会被裁剪,第二次它会很好地显示信息。

或者例如,方向为人像,当我转向风景并返回人像时,所有内容都会显示.. < / p>

这是我使用的代码。

private void Default_Loaded(object sender, RoutedEventArgs e)
    {
        //  Only need to reset web page when creating a new info page (coming from Info index or tombstoned app):
        if (_newPageInstance && (NavigationContext.QueryString.Count >= 1))
        {
            //  Set html page for web browser control based on park and page # passed in:
            if (_parkId.Length <= 0)
            {
                _parkId = App.MapModel.InfoParkId;  //  App.ViewModel.CurrentPark.ParkId might not be ready if tombstoned
                _parkPage = Convert.ToInt32(NavigationContext.QueryString.Values.First());
                SubTitle.Text = App.MapModel.InfoPageTitle; //  set title like "Legend" for this page
            }
            //  else - these 3 values were set during OnNavigatedTo when returning from tombstoning
            //
            Browser.Base = Constants.ParkInfoDirectory;    //  "ParkInfo" folder
            string s = string.Format("{0}/section_{1}.html", _parkId, _parkPage);    //  URL = "/ParkInfo/ti217/5" for page 5 of Rainier

            Browser.Navigate(new Uri(s, UriKind.Relative));

            //Browser.Navigate(new Uri(s, UriKind.Relative));
        }

        //var myHeight = this.ActualHeight;

        //Browser.Height = ((StackPanel)Browser.Parent).ActualHeight;

        this.Browser.UpdateLayout();

        this.ContentPanel.UpdateLayout();
    }

    // Executes when the user navigates to this page (or coming back from being tombstoned):
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        if (ParkMaps.App.ViewModel.CurrentPark != null)
        {
            //  Set title bar to use this park's name:
            PageTitle.Text = ParkMaps.App.ViewModel.CurrentPark.ParkNameUpper;
        }
        else PageTitle.Text = "Park Maps";
        // If the constructor has been called AND the PreservingPageState key is in the State dictionary,
        // then the UI state for this page should be restored:
        if (_newPageInstance && this.State.ContainsKey("PreservingPageState"))
        {
            //  Restore the state of the UI:
            try
            {
                _parkId = Utilities.TryGetValue<string>(State, "InfoParkId", "ti217");
                _parkPage = Utilities.TryGetValue<int>(State, "InfoDetailsParkPage", 0);
                SubTitle.Text = Utilities.TryGetValue<string>(State, "InfoDetailsSubtitle", "Park Info");
                //  NOTE: Browser not ready yet, so load web page in Default_Loaded above
            }
            catch { } //  Don't restore anything if had trouble above
        }
    }

这是XAML

                                           

    <StackPanel Orientation="Vertical"  Grid.Row="0">
        <StackPanel x:Name="TitlePanel" Margin="8,4,8,4" Orientation="Horizontal">
            <Image Source="{Binding LogoImageSource}" ManipulationCompleted="LogoBar_ManipulationCompleted" Width="208" Stretch="Uniform" HorizontalAlignment="Left" Margin="9,0,0,0"/>
            <TextBlock x:Name="PageTitle" Text="Park Maps" ManipulationCompleted="LogoBar_ManipulationCompleted" Width="250" Margin="-8,4,0,4" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="NoWrap" TextAlignment="Right" HorizontalAlignment="Stretch" />
        </StackPanel>
        <TextBlock x:Name="SubTitle" Text="Legend" Margin="9,6,9,9" Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="Wrap" TextAlignment="Center" />
    </StackPanel>


    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" MinHeight="697" VerticalAlignment="Stretch" >



    </Grid>
</Grid>

1 个答案:

答案 0 :(得分:1)

如果我已正确理解您的问题,您需要添加:

 Stretch="Fill"

到您的XAML。

如果我不理解你的问题,请重新解释这个问题,因为你想要实现的目标并不明显。

由于