我有一个简单的html页面加载到Windows Phone中的webview控件,它不会缩放到全屏,并且会出现一个白色的补丁(如附图所示)。
<Page
x:Class="loadtime.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:loadtime"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView x:Name="mainWebView"></WebView>
</Grid>
html:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body style="background-color:red; border: 1px solid blue;">
</body>
</html>
可能是什么原因?是否还需要启用其他属性?
答案 0 :(得分:1)
您需要将WebView HorizontalAlignment
和VerticalAlignment
设置为Stretch
以下是我的完整代码。
<强> XAML 强>
<Page
x:Class="App16.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App16"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Loaded="Page_Loaded"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView x:Name="mainWebView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Grid>
</Page>
代码背后
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App16
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
string Loaded = "<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta charset=\"utf-8\" /><title></title></head><body style=\"background-color:red; border: 1px solid blue;\"></body></html>";
mainWebView.NavigateToString(Loaded);
}
}
}
以下是输出。
答案 1 :(得分:0)
问题是状态栏,这解决了问题。
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
await StatusBar.GetForCurrentView().HideAsync();
}
答案 2 :(得分:-1)