---
title: "WebBrowser control in WPF"  
description: "Sometime may we require that we want to open some html document in my own application. To perform this task WPF introduce a new control named WebBrows"  
author: "Anonymous User"  
published: 2011-04-03  
updated: 2019-12-10  
canonical: https://www.mindstick.com/articles/530/webbrowser-control-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 3 minutes  

---

# WebBrowser control in WPF

Sometime may we require that we want to open some html [document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool) in my own [application](https://www.mindstick.com/articles/12824/calculator-application-in-android). To perform this task WPF introduce a new control named WebBrowser control through which we can open all the html [documents](https://www.mindstick.com/articles/156931/the-main-types-of-business-documents) [as well as](https://www.mindstick.com/forum/156547/difference-between-max-width-and-width-as-well-as-max-height-and-height) we can open any sites. One thing more that WPF WebBrowser control supports clientside [scripting](https://www.mindstick.com/blog/183/cross-site-scripting) also. In this article am going to explain you that how can we use WebBrowser control in WPF.\

##### Working Explanation

To implementing this application I had added one TextBlock which shows a read only message, one [TextBox control](https://www.mindstick.com/articles/320/textbox-control-in-vb-dot-net) in which user can enter any URL, one WebBrowser control in which we can show output of the request and two buttons named Load Requested Site and Load Default Site. When user click on Load Default site then [Google home](https://www.mindstick.com/blog/33285/how-to-setup-google-home-smart-device) page is opened and when user click on Load Requested site then Requested site whose address is given in textbox control is opened.

##### XAML code snippet for creating user interface

```
<Grid>        <Grid.Background>            <LinearGradientBrush MappingMode="RelativeToBoundingBox" EndPoint="0.5,1" StartPoint="0.5,0">                <GradientStop Color="Azure" Offset="0"/>                <GradientStop Color="Chartreuse" Offset="1"/>            </LinearGradientBrush>        </Grid.Background>        <Grid.RowDefinitions>            <RowDefinition Height="0.091*" />            <RowDefinition Height="0.775*"/>            <RowDefinition Height="0.154*"/>        </Grid.RowDefinitions>        <Grid.ColumnDefinitions>            <ColumnDefinition Width="150*" />            <ColumnDefinition Width="353*" />        </Grid.ColumnDefinitions>        <TextBlock x:Name="txbUrlInfo" Height="30" Text="Eneter URL : " Grid.Row="0" Grid.Column="0" />        <TextBox x:Name="txtUrlInfo" Height="30" Width="350" Grid.Row="0" Grid.Column="1" />        <Border x:Name="broserBorder" Grid.Row="1"   Grid.ColumnSpan="2" Grid.Column="0" BorderThickness="5" >            <WebBrowser x:Name="browser1" Cursor="Pen" />        </Border>        <Button x:Name="btnLoadSite" Width="150" Height="30" Content="Load Requested Site" Grid.Row="2" Grid.Column="0" Click="btnLoadSite_Click" />        <Button x:Name="btnDefaultSite" Width="150" Height="30" Content="Load Default Site" Grid.Row="2" Grid.Column="1" Click="btnDefaultSite_Click" /></Grid>
```

##### Steps to create this code snippet

- Firstly I had divided Grid control in Three Rows and Two columns.
- In first row I had put one Text Block control for displaying a read only message and one textbox control in which user entered location of [web site](https://www.mindstick.com/articles/12285/the-finest-web-site-design-trends-you-may-expect-in-2017).
- In second row I had put a border control because [web browser](https://answers.mindstick.com/qa/95505/what-are-the-pros-and-cons-of-using-safari-web-browser) control does not provide border that’s why we have to added border control then inside border control we added WebBrowser control in which output needs to be displayed.
- In third row I had put two Buttons one named Load Requested Site and another one is Load Default Site.

##### Code to Load Requested Site

```
private void btnLoadSite_Click(object sender,  RoutedEventArgs e)        {            try            {                browser1.Navigate(new Uri(txtUrlInfo.Text, UriKind.RelativeOrAbsolute));            }            catch (UriFormatException ue)            {                MessageBox.Show(ue.Message);            }            catch (Exception e1)            {                MessageBox.Show(e1.Message);            }}
```

##### Code to Load default site

```
private void btnDefaultSite_Click(object sender,  RoutedEventArgs e){            browser1.Navigate(new Uri("http://www.google.com"));}  
```

##### Output of the above code snippet is as follows

![WebBrowser control in WPF](https://www.mindstick.com/mindstickarticle/3610ee37-4b56-41fd-99b1-c4805b016901/images/e76d3b22-9b45-4290-81d4-5e788a61aaff.png)

##### Loading default google site when user click on Load Default Site

![WebBrowser control in WPF](https://www.mindstick.com/mindstickarticle/3610ee37-4b56-41fd-99b1-c4805b016901/images/fcfad112-ed84-4246-b59f-e9e9fe482721.png)

##### Loading Microsoft home page when user click on load requested site and address is entered in textbox.

![WebBrowser control in WPF](https://www.mindstick.com/mindstickarticle/3610ee37-4b56-41fd-99b1-c4805b016901/images/c56ca40d-762c-420b-a1d4-69f986c5fbc4.png)

---

Original Source: https://www.mindstick.com/articles/530/webbrowser-control-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
