Skip to content

Visual Studio 2012 – New Silverlight Web Part project template

February 17, 2012

The Visual Studio 2012 has a new feature, called Silverlight Web Part project template

As described by MSDN:

New Silverlight Web Part project template. The new Silverlight Web Part project template makes hosting a Silverlight application in a web part easier and more convenient. The project template enables you to create a new Silverlight application or provide your own, and it also provides a web part project with which to associate the Silverlight application.

Here is a short tutorial for this new feature.

First let’s create a new SharePoint 2010 project:

Let’s add a new Silverlight Web Part to the project:

Visual Studio then automatically prompts to select the Silverlight application that you want to show in the web part. We don’t have one ready, so let’s select the option to create a new one

Open the MainPage.xaml in the Silverlight project.
Drop a button to the designer.
Give a name to the button like “btn”.
Double click on the button to create a click eventhandler.

Open the MainPage.xaml.cs file. Update the Button_Click eventhandler like this:

private void Button_Click(object sender, RoutedEventArgs e)
{
    this.btn.Content = "Hello World";
}

And it’s done. Build and deploy the solution to install the Silverlight application and the web part.

Note, that a new feature was automatically added to your SharePoint project which contains the new web part. This is activated on your site collection automatically during deployment form VS.

When the deployment is completed open the SharePoint site and add the web part to a page:

Save the page and try the web part. It should look like this:
(scroll down to the bottom of this post if an error occurs)

Click on the button to test the web part:

Great. So easy.

Troubleshooting

When opening the page with the Silverlight web part you may get this error:

Could not download the Silverlight application or the Silverlight Plugin did not load.

To re-configure the Web Part or to provide a different Silverlight application (.xap), open the tool pane and then click Configure

This is usually just a caching problem. Refresh the page several times, restart the browser if the refresh is not enough and it should be ok.

Advertisements
Leave a Comment

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

%d bloggers like this: