Skip to main content

Cloud

Set Silverlight “PluginNotInstalledTemplate” in code behind

Silverlight 2 and 3 provide a Silverlight server side control that takes care of generating Silverlight object tag and all the necessary components in the HTML for you. The control also provides a default template that is automatically displayed to the users who don’t have Silverlight plug-in installed on their machines.

image
Figure 1: Default Silverlight Install Experience

The default template works, but it doesn’t look good and it doesn’t contain any of your company’s branding. Wouldn’t it be nice to show your own custom template with your company’s branding instead of the default Silverlight logo? Fortunately, customizing the default template is easy. Many companies do that. Microsoft.com home page is an excellent example:

image
Figure 2: Microsoft.com Silverlight Install Experience as of 08/12/2009

There are hundreds or articles available on the web on how to customize the template, so I am not going to talk about it in this blog. A quick web search will get you a bunch of links in just a few seconds. Here are a couple that I just found:

  1. http://silverlight.net/blogs/msnow/archive/2008/09/10/silverlight-tip-of-the-day-38-how-to-customize-the-silverlight-install-experience.aspx
  2. http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2008/09/01/Silverlight-Install-Experience-for-MSDN-East-Coast-News.aspx

Essentially, all you need to do is to create a HTML markup and set the “PluginNotInstalledTemplate” property on Silverlight control to use your HTML markup, but what if you want to do this at runtime or in the code behind. You can’t just set “PluginNotInstalledTemplate” property to use your HTML markup string; it is expecting an object of type ITemplate.

Here is how you can do it. Create a small component that drives from ITemplate interface and accepts your HTML as input and then use that object to set the “PluginNotInstalledTemplate” property in the code behind. The code in figure 3 does exactly that. You can just copy it and use it.

image
Figure 3: Silverlight ITemplate component

The code snippet in figure 4 shows how you can use the object above to set your custom template in code behind.

image
Figure 4: Setting Silverlight PluginNotInstalledTemplate in code behind. Here “sl” is a Silverlight control and “pluginNotInstalledTemplate” parameter is a HTML string.

That’ all there is to it.

Hope this helps.

Talha

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.