Two ways I can think about is,
Create a "Shell"
Host the HTML Page with Silverlight, in a Winforms desktop application, using a web browser control, and communicate to and fro using HTML DOM. Then I can request the hosted shell to do things like printing. See details here
Mono also has a web browser control - based on FireFox XULRunner instead of IE - not yet succeeded in loading Silverlight inside that. Another option might be using Webkit.
Embed a web server
Embed a light weight web server with in the Host application, and handle requests to perform such operations. You can probably define a protocol on top of HTTP for things like saving to a local folder, sending data to print etc.
Here is a trick you could use.
- Make sure your Silverlight Views and View Models are isolated within their own assembly that is easily referenceable by your WPF application.
- Add a reference to the Silverlight class library that houses the Views & View Models in the WPF application.
Move the contents of the UserControl, "CustomerView" into a DataTemplate housed in a resource dictionary called "customerViewTemplate"
Inside your root UI element XAML files in Silverlight and WPF do this:
<ContentControl ContentTemplate="{Staticresource customerViewTemplate}" />
- In the Silverlight application's App.xaml make sure to add the following Resource Dictionary reference to the merged dictionaries.
<ResourceDictionary Source="MyApp.Views;component/CustomerViewResources.xaml" />
- In the WPF application's App.xaml make sure to add the following resource dictionary reference to the merged dictionaries.
<ResourceDictionary Source="pack://application:,,,/MyApp.Views;component/CustomerViewResources.xaml" />
Sorry about the numbering, looks like Stack Overflow's ordered list mechanism is a little off.
The reason why this works is because you can't directly reference a Silverlight UserControl from XAML within WPF. It will give you the following error:
'Cannot resolve dependency to assembly
'System.Windows, Version=2.0.5.0,
Culture=neutral,
PublicKeyToken=7cec85d7bea7798e'
because it has not been preloaded.
When using the ReflectionOnly APIs,
dependent assemblies must be
pre-loaded or loaded on demand through
the ReflectionOnlyAssemblyResolve
event.
If you try to force the UserControl onto a WPF Grid using C# you will get the following 3 errors:
The best overloaded method match for
'System.Windows.Controls.UIElementCollection.Add(System.Windows.UIElement)' has some invalid arguments.
The type
'System.Windows.Controls.UserControl'
is defined in an assembly that is not
referenced. You must add a reference
to assembly 'System.Windows,
Version=2.0.5.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e'
cannot convert from
'ToWpfTest.Views.TestView' to
'System.Windows.UIElement'
I gather this is because the System.Windows.UIElement in WPF is not the same as the System.Windows.UIElement in Silverlight.
Best Answer
Also mentioned was this quote:
News media frequently twist facts, or mention only selected facts, as a way of making the story better. Silverlight is not dying off, and the HTML5 spec has not been ratified.
One could also draw the conclusion from that article that MS are doing their best to manipulate the HTML5 spec to suit themselves and we will end up with a situation like we had in the past: everyone implements the same spec in a different way and you need to code workarounds for each major browser. Because of this wrangling (which other vendors will no doubt also be doing) it may take a long time for the spec to be fully ratified.
Having said that, WPF is not subject to any of this uncertainty - but it still isn't cross platform. So you have to ask yourself these questions:
LOB apps tend to be quite tightly spec'd and controlled to specific setups, so a long term change of focus for Silverlight may not affect you that much at all.
EDIT: the day after i answered this question, Colin Eberhardt wrote this very good blog post: Does HTML5 mean the end is in sight for Silverlight? which covers this exact news story / quote. Colin also references this follow up blog post from Bob Muglia1 which elaborates on what he was quoted as saying. I think you can safely conclude that it is absolutely fine to develop your LOB app in Silverlight if you want to :)
1 President of the Server and Tools Division at Microsoft