C# – Thoughts about using Silverlight In Desktop Apps

cnetsilverlightsilverlight-2.0

To summarize, as we all know,

a) Silverlight is expected to be hosted by a browser, and runs in an isolated sandbox so that there won’t be any security issues

  1. Silverlight don’t have direct access
    to the file system, other than the
    isolated storage area
  2. There is no
    direct way to open common dialog
    boxes like File Save in Silverlight (Though Opendialog box is supported).

b) Silverlight can’t access local resources like a printer

What are the ways to go beyond the sandbox, so that I can host a Silverlight application locally, to read files and save them back if required, to hand over data to a printer, and so on..

Update:

Is full WPF is not an option for me? No. I'm also interested in a cross platform solution – for instance, you could host Silverlight in Mono Web browser control, so that you can run it virtually anywhere.

The idea is to re-use the same application that I'm building for web in my desktop as well, by providing separation of concerns at some areas – like persistence, resource access etc.
Scenarios:

1- Some kind of gadget container, with access to local resources.
2 – A desktop Silver light based media application

Update:

I just did a POC to enable me to access printer and save files locally, of course through a shell where I'm hosting my Silverlight application. If you wan't you can have a look at the post here in my blog

Best Answer

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.

Desktop Shell

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.

Embedding A Server