Click here to Skip to main content
15,890,947 members
Articles / Programming Languages / C#
Tip/Trick

Working On WebView Component in Windows Application

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
11 Jul 2016CPOL 7.4K   4  
Working on Webview component

Introduction

WebView is a component which is used for rendering a web page in a Mobile Phone or Desktops.

Background

The following are the important steps to be followed.

Step 1

Open Visual Studio 2013 (till Visual Studio 2015).

Step 2

In Visual Studio, click New Project option.

Image 1

Step 3

In the New Project wizard, select Windows universal blank application and give the project name as Webview.

Image 2

Step 4

Choose the Minimum Windows 10 SDK Version as Windows 10 Build 10240 and click Ok.

Image 3

Step 5

Once the project is loaded completely, then open the MainPage.Xaml from Solution Explorer.

Image 4

Step 6

From the toolbar, select Webview, Textbox and button as shown below.

Image 5

Image 6

Using the Code

Now give name for button, Textbox and Webview as shown in the given code.

MainPage.xaml

XAML
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <WebView x:Name="Webview" HorizontalAlignment="Left" Height="584" 
         Margin="10,126,0,0" VerticalAlignment="Top" Width="1260"/>
        <TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="388,32,0,0" 
         TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Height="45" 
         Width="428" InputScope="Url"/>
        <Button x:Name="button" Content="Search" HorizontalAlignment="Left" 
         Margin="845,38,0,0" VerticalAlignment="Top" Click="button_Click"/>
    </Grid>

MainPage.Xaml.cs

Write the following code in the search button event.

C#
String URL = textBox.Text;
Webview.Navigate(new Uri(URL, UriKind.Absolute));

Step 7

Once the coding is completed, then click debug option and don't forget to verify Debug architecture as X86.

Image 7

The output is as shown below:

Image 8

It navigates to codeproject.com:

Image 9

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
-- There are no messages in this forum --