![](/img/trans.png)
[英]c# UWP - Tiles OnNavigatedTo doesn't keep variables in MainPage
[英]C# UWP WebView Not appearing on UWP mainpage
I am working on webview control in C# UWP app. Everything was working. All at a sudden webview stop showing the webpage on the window. I tried creating one more app and rewrite the code once more. But it's not working now.
Below is the code.
<Page
x:Class="hello.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:hello"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid >
<WebView x:Name="webView" Source="http://www.www.bing.com" />
</Grid>
</Page>
错误:我也尝试使用其他 URL。 试过 webView.Navigate(new Uri(" http://www.bing.com ")); 在 cs 文件中也是如此,但 webview 根本没有出现在窗口中。 搜索了很多,但没有得到任何解决方案。 所有断点都被正确命中,并且在运行时不会抛出任何错误。 手动清理调试文件夹并再次重建应用程序......但没有运气。 有人可以帮我解决这个问题吗?
C# UWP WebView 未出现在 UWP 主页上
我检查了你的代码,我发现你传递了错误的 uri http://www.www.bing.com
,如果你想让 webview 填充Grid
你需要设置VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
,我编辑了您的代码,它可以工作,请参阅以下内容。
<Grid>
<WebView
x:Name="webView"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Source="http://www.bing.com"
/>
</Grid>
您可以在页面加载事件中调用webView.Navigate(new Uri("http://www.bing.com"))
方法,并在 xaml 代码中删除上面的Source
属性。
private void Page_Loaded(object sender, RoutedEventArgs e)
{
webView.Navigate(new Uri("http://www.bing.com"));
}
请注意您的 WebView 将访问互联网,因此您需要检查互联网能力。
非常感谢,互联网是根本原因,补充说解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.