Tuesday, September 14, 2010

Simple web Browser with Animation using WPF

Dear Friends,
How are you ?
Today we will create a simplest web browser in WPF with some basic animation handling.
To do this task we have a simple control which is webBrowser control.
We need to just drag & drop webBrowser control and design the screen as you need just check out below fig.

once you done with the design.
Then to open a web page in browser control you need navigate method provided by webbrowser control.
The navigate method has string, uri parameter so you can utilize that according to your need.
Just check out below code.

The browser control also maintain forward , back history which we can utilize according to our need. Please see below code for that.

We can very much customize the web browser like block particular URL , bookmark etc.
Now you are just wondering that what is animation here ? so I would like to say that WPF give us tremendous opportunity for eye catching look and animation.
It give approx. 32 different animation object which is helpful in different scenario. All are available with name space “System.Windows.Media.Animation
”. Here I am with One of the simplest object which is double Animation.
The double animation is just basic animation control which can be utilize for animation you can do it with either XAML or code.
Here I am giving example of code.
So check out below code.
Dim da As New DoubleAnimation()
da.From = 30
da.To = 300
da.Duration = New Duration(TimeSpan.FromSeconds(1))
Me.wbctrl.BeginAnimation(WebBrowser.HeightProperty, da)
da.AutoReverse = True
da.RepeatBehavior = RepeatBehavior.Forever

Here wbctrl is webBrowser control . The double animation has duration property for how much time it will take. It has auto reverse property to
In the above code we using height property animation . just see below line
Me.wbctrl.BeginAnimation(WebBrowser.HeightProperty,da)

In similar manner you can go for width , position , opacity etc.
For more detail information please download attached code at

Enjoy coding.
Thanks
Rajat jaiswal
The Suburbs