简体   繁体   中英

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>

ERROR : I tried using other URLs as well. Tried webView.Navigate(new Uri(" http://www.bing.com ")); in the cs file as well , but webview is not at all appearing in the window. Searched a lot but did not get any solution. All break points are getting hit properly and it's not throwing any error while running. Cleaned the debug folder manually and rebuild the app again .. but no luck. Can someone help me to fix the issue ?

C# UWP WebView Not appearing on UWP mainpage

I checked your code, I found you have passed wrong uri http://www.www.bing.com , and if you want to make the webview fill the Grid you need set VerticalAlignment="Stretch" HorizontalAlignment="Stretch" , I edited your code, and it works, please refer the following.

<Grid>
    <WebView
        x:Name="webView"
        HorizontalAlignment="Stretch"
        VerticalAlignment="Stretch"
        Source="http://www.bing.com"
        />
</Grid>

You could call webView.Navigate(new Uri("http://www.bing.com")) method in the page Loaded event, and remove above Source property in xaml code.

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    webView.Navigate(new Uri("http://www.bing.com"));
}

Please note your WebView will access internet, so you need check internet capability.

非常感谢,互联网是根本原因,补充说解决了问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM