2012-02-28 238 views
-1

我想知道为什么我第一次尝试使用WebBrowser加载信息,页面被裁剪,第二次它显示的信息很好。Webbrowser控件不显示整个页面?

或者例如,方向是肖像,当我转景观,回到肖像一切都显示..

这是我使用的代码。

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

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

Stretch="Fill" 

到您的XAML。

如果我还没有理解你的问题,请重新说明这个问题,因为它不是你想要达到的目标。

谢谢

+0

我在哪里添加这个? – Kiwimoisi 2012-02-29 09:54:19

+0

因为在网格或webrowser中没有属性STRETCH .. – Kiwimoisi 2012-02-29 09:54:37