Silverlight Out of Browser with new WebBrowser

27 11 2009

Today I’m making a demo application. It’s a simple PDF reader in Silverlight and it uses two new features. The Silverlight Out Of Browser (SLOOB) with elevated permissions, and the WebBrowser Control. Those of you who’ve written some WPF might already be familiar with the WebBrowser control and what it can do. In Silverlight, it’s basically an html-renderer for when you’re out of browser.

SLOOB

Let’s start by making a new Silverlight application. Create it with a website attached to it. First some basic XAML code to create the WebBrowser control:

<Grid x:Name="LayoutRoot" Background="White" Margin="50">

<Border BorderBrush="Black" BorderThickness="10" >
   <WebBrowser Name="myBrowser"/>
</Border>

</StackPanel>

I’ve chosen to add a margin and a border for increased visibility and separation.

Try and run this application. You’ll see how the WebBrowser control does nothing while in browser.

Capture

Now go to your Silverlight project file and select Properties. You’re going to allow OOB deployment.

2

Next, restart your application and install it to your desktop.

3

This next part is important, set your Silverlight project file as your startup and go back into Properties. This time go to the Debug menu and select your OOB program as the default debug target. This way you won’t have to reinstall it every time you’ve made a change.

4

Lastly, simply set myWebbrowser’s source to a pdf file located in your Client Bin.

<WebBrowser Name="myBrowser" Source="example.pdf"/>

image
Now relaunch your application and you’ll find you have a fully functional PDF viewer with separate interaction areas. This means that the context menu for the PDF viewer is separate from the one in Silverlight.

5

Where you go from here is up to you. Good luck!

About these ads

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

Join 86 other followers

%d bloggers like this: