Tushar Kanta Gupta
Tushar Kanta Gupta

Reputation: 7

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 ?

Upvotes: 0

Views: 1141

Answers (2)

Nico Zhu
Nico Zhu

Reputation: 32775

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.

Upvotes: 1

Tushar Kanta Gupta
Tushar Kanta Gupta

Reputation: 7

Thanks very much , Internet was the root cause , adding that solved the problem.

Upvotes: 0

Related Questions