c# - C# UWP WebView 未出现在 UWP 主页上
问题描述
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>
您可以在页面加载事件中调用 方法,并在 xaml 代码中webView.Navigate(new Uri("http://www.bing.com"))
删除上述属性。Source
private void Page_Loaded(object sender, RoutedEventArgs e)
{
webView.Navigate(new Uri("http://www.bing.com"));
}
请注意您的 WebView 将访问互联网,因此您需要检查互联网功能。
推荐阅读
- java - 如何从自定义子注释中获取值?
- python - `django-constance` 在发行版中,它不生成数据。
- c# - 如何使用 C# mvc 在电子邮件中使用 HTML
- browser - 你可以在浏览器中嵌入 GraalVM 应用程序吗?
- performance - 如何提高 pandas 搜索过程的速度?
- cumulocity - CEL中如何设置小数点
- php - 我怎样才能简化这个关于预订的查询?
- javascript - React:如何从导入的文件中为道具添加新值?
- javascript - 如何将 jquery 对象呈现为 html - 查看 [object Object]
- android - 如何将 ffmpeg gl-transition 项目集成到我现有的项目中