Jump to content
  • Advertisement
Sign in to follow this  

[.net] Exposing a WPF/MVVM Application To A Web/(Silverlight) UI

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a WPF application which I've structured using the MVVM design pattern. I would eventually like to extend the application in such a way that it will listen on an HTTP port, and allow remote users to make modifications via a Silverlight client. In order to accomplish this, I have a number of unknowns:

1) Are there any built-in .NET classes which I can use to easily instantiate a "server" object in the WPF application, in order to listen for HTTP requests?
2) Would there be any special steps required, to host a silverlight application from inside my WPF executable?
3) The end goal would be to have any changes made in the Silverlight interface automatically appear in the WPF user interface - I would ideally like to accomplish this by sharing the ViewModel objects between both the Silverlight and WPF Views, but I'm not sure if that is possible (would there be binary compatibility issues?).

Thanks in advance for your thoughts,


Share this post

Link to post
Share on other sites
Depending on the level of complexity, you might be better refactoring the model part of as a web service that both front ends access.

There are a couple of options you could look at also.
  • XBAP, kinda heavy weight as a web client, but involves the least work on your part (assuming you don't need full trust)
  • refactor the entire app as silver light and use out of browser on the desktop
    To answer your questions:
    1) Not sure, but as I said this is generally done by writing a web service rather than hosting a web server in your wpf app
    2) You can host your silverlight content in a WPF WebBrowser control, but I'm not sure about communicating with the content (i.e. calling methods on your silverlight classes)
    3) You can share code between WPF and silverlight, but it's not easy. Silverlight runs on a different CLR to "regular" .net apps. You can share the code files by adding them as links in two seperate projects (one silverlight, one wpf) but that you will need to be careful to only use code that silverlight supports.

    TBH, it's a bit of a pig. The silverlight restrictions can seem kinda arbitrary (for instance, this overload of string.compare isn't in silverlight, despite just being a forwarding call to this overload). Last time I tried it, I found it near impossible to reuse xaml across the two platforms, mostly due to namespace inconsistencies. In short you can do it, but you'll end up hamstringing your wpf interface to work with silverlight so much that you'll either keep the UXs separate or just using one.

    Best of luck.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!