View Web Pages Using WebView In UWP

Here are the steps: 

Step 1: Firstly, we'll create our Universal Windows Blank Project and name it according to our choice.



Step 2:
The next thing we'll do in our project is to define our Grid Rows using Grid.RowDefination. In my case I've used two rows: one for our browser display and the other is for search box and search button.
  1. <Grid.RowDefinitions>  
  2.     < RowDefinition Height="*">  
  3.         < /RowDefinition>  
  4.         < RowDefinition Height="0.1*">  
  5.     < /RowDefinition>  
  6. < /Grid.RowDefinitions>   

Step 3: The interesting thing we are going do in our project is to add one new control, that is WebView. The purpose of this control is to display your html web pages in your application. You must name your WebView control in your project.

  1. <WebView Name="mywebview" />   

Step 4: The next thing is to add a TextBox in which you type some Url.

  1. <TextBox Name="searchbox1" Grid.Row="1" PlaceholderText="Search here" FontSize="18"  
  2.    Width="250" HorizontalAlignment="Left" />   

Now create a button click event for your search button. Once you create a button click event then you've to go to the backend of your XAML page i..e., your csharp page.

  1. <Button Name="searchbtn" Grid.Row="1" Click="searchbtn_Click"  
  2.    HorizontalAlignment="Right"  
  3.    Width="100" Height="80" Content="Search"  
  4.    FontSize="25" FontWeight="Bold" />   


Step 5:
Once you enter in your button, click event, then you must declare a string variable and assign your TextBox name to it along with Text property.
  1. string site = searchbox1.Text;  
Step 6: The next thing is you call the Navigate method along with your WebView name and pass the string variable into Navigate method along with UriKind Absolute.
  1. mywebview.Navigate(new Uri(site,UriKind.Absolute));  


Step 7:
Now run the app by pressing F5. Now go to your searchbox and type some URL and press your button  -- whatever name you gave to it --  and your result will display in webview.

Ebook Download
View all
Learn
View all