|
In the era of Silverlight 2 there were a few initiatives to get Silverlight working outside the browser. Although those were basically applications that hosted a Webbrowser component inside the application which was the host for the Silverlight application. Silverlight 3 has out of browser support natively. This article explains what can be done, and what can’t be done by using this feature. Everything is based on the first Beta of Silverlight 3.
There still is some work that needs to be done in making the exceptions informational. I tried to bring my Silverlight Application out of the browser, but I didn’t have the necessary information in the appmanifest.xml yet.
I did change the appmanifest.xml to be like this.
<Deployment
xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Deployment.Parts>
</Deployment.Parts>
<Deployment.ApplicationIdentity>
<ApplicationIdentity
ShortName="MM Silverlight 3 Experiments"
Title="MM - Experiments">
<ApplicationIdentity.Blurb>This application is meant for handling experiments in Silverlight.
</ApplicationIdentity.Blurb>
</ApplicationIdentity>
</Deployment.ApplicationIdentity>
</Deployment>
After I tried to bring it out of the browser with this code.
I got this window, asking me if I want a short cut on the desktop and start menu.
This is what it looks like when running in the browser.
This is what it looks like when running outside the browser.
Out of browser Javascript or HTML Dom manipulation?
I think it’s really interesting to know if Javascript is supported out of the browser. Because when in the ages of Silverlight 2 I called Javascript every once in a while because I was trying to do something that wasn’t supported in Silverlight. But be careful, Javascript isn’t supported in out of browser mode. You will get an error similar to this. The same goes for HTML Dom manipulation, it’s not supported as well.
Are we online or offline?
You can very easily get the current state of the network connection by using this code:
NetworkInterface.GetIsNetworkAvailable();
If you want to detect changes in the state of the network connection you can make use of the NetworkAddressChanged event.
NetworkChange.NetworkAddressChanged +=
(sender, args) =>
Dispatcher.BeginInvoke(() =>
{
stateTextBlock.Text = string.Format("Online:{0}", NetworkInterface.GetIsNetworkAvailable());
});
I test this and it really works. I remember I tried creating a listener for changes in the network connection, but it never made it ;-).
Auto-update
One of the features that’s supported is the auto-update feature. Yes this is really auto-update. You cannot stop the update from happening right now. One of the things that’s important to know though is how it’s actually implemented. It’s actually making use of metadata that’s retrieved inside the HttpResponse. To be precise it’s making use of the ETag field.
Because it’s making use of the ETag field, you’ll have to remember this will only work when running your Silverlight application inside a webserver. When accessing the generated html page, it won’t work. Because this is accessed through the local file system. Like this:
Besides that, I wasn’t even able to get it working using Windows Server 2008 as a client at all. When running on Windows XP as a client it is working though. And I’ve read reports it’s working Windows 7 as well. Don’t know if this is one of the beta bugs. I understood from Tim Heuer there’s a known issue with running from localhost.
Init Parameters
So what do we have left that has kind of different behavior compared to browser instances of Silverlight? The Init Params, this is a parameter that can be set in the Javascript or as param in the object used for initializing the Silverlight Application. The values can be read inside your application.
But when you try to access the values out of browser you won’t get the values you were expecting. Or at least, I’m not sure anymore what I was expecting. But in the end this doesn’t work either.
Out of browser support is nice but…
I really like the out of browser support. But we have to keep in our mind what is supported and what isn’t. Javascript and Dom manipulation isn’t supported, although this seems to be logical because we are living outside the browser, a lot of workarounds for missing feature won’t work anymore. Besides that the initparams is completely useless outside the browser.
Ps. This article is cross posted on: Mark Monster’s blog and Silverlight Help.
|