1

I decided to convert the WPFs into a Silverlight applications. My only problem is trying to get it to display the silverlight application in my MVC web browser. I added all of my silverlight projects into my MVC project. I am just not getting it to show my silverlight application. Can someone tell me what I am doing wrong in my asp part in my CSHTML

<h2>System</h2>
 <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
  <div id="silverlightControlHost">
     <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="1000" height="800">
        <param name="source" value="/ClientBin/System.xap" />
        <param name="onError" value="onSilverlightError" />
        <param name="background" value="white" />
        <param name="minRuntimeVersion" value="5.0.61118.0" />
        <param name="autoUpgrade" value="true" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none" />
        </a>
     </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
  </div>
</asp:Content>

I even tried to get the full source path from the root folder of the project I added.

<param name="source" value="/System/System.Web/ClientBin/System.xap" /> 

It still won't display the silverlight application.

The other thing I notice is runat="server", the runat has a green underline and says:

ASP.NET attributes are only allowed in ASP.NET files.

I don't know if it is suppose to do that or not.

I got how to embed a Silverlight into a MVC from here

2 Answers2

1

Although it is technically possible to embed WPF inside a website in the form of a Silverlight application, but this should be prevented where possible, see 8 reasons to avoid Flash (or Silverlight) like the plague when designing a website. This and this are also a good read.

Silverlight apps also run in a sandboxed environment, meaning each "page" in your situation will be a different "application". You still will have to rewrite and implement web specific controllers and views to host each Silverlight component. It is advised to consider a rewrite.

Fanie Reynders
  • 580
  • 3
  • 16
  • I understand the problem with a WPF, that is why I am making those applications into a silverlight. I was told you can display a silverlight.aspx in a MVC. Silverlights give me way more features then what I can do with a MVC. I can get the silverlight application to work and display everything but when I try to display that in the MVC is my only problem at this point. Which my code for displaying it is above. – DotNet Programmer Jun 16 '15 at 22:03
  • 1
    You cannot mix desktop and web technologies and expect them to seamlessly work together. Like I've mentioned you can display a Silverlight app inside HTML but it will run in its own sandboxed environment as a different application. Silverlight is just a fancy web based host for WPF applications and like Flash (which is dead now) it's bad in my opinion. – Fanie Reynders Jun 16 '15 at 22:16
  • 1
    This answer would me more useful with some sources to back up its claims. As it stands, it does not provide a well documented answer that stands above individual opinion. – Jeff Yates Jun 17 '15 at 13:43
  • @JeffYates can you please elaborate more on specifically what you mean so I can edit the answer to improve it? – Fanie Reynders Jun 17 '15 at 13:53
  • He is basically saying that you are making claims that having a silverlight application inside a MVC application is bad practice. He wants you to add sources that justify that doing this really is a bad practice. Otherwise how you have it right now its just your opinion. – DotNet Programmer Jun 17 '15 at 14:11
  • Then how hard is it to make a grid view in MVC? – DotNet Programmer Jun 17 '15 at 15:21
  • Quite easy, see http://stackoverflow.com/questions/177275/grid-controls-for-asp-net-mvc – Fanie Reynders Jun 17 '15 at 15:23
  • Well I got the MVC to work with the silverlight. I will convert it all to that and get it working that way for now. Later I will start converting page by page to full MVC but I don't have a year to get this website out there for my company to start using. They need something right now. Thank you for your help. – DotNet Programmer Jun 17 '15 at 18:37
  • That seems like the most fitting solution :) – Fanie Reynders Jun 17 '15 at 19:05
  • How do you get it where you can send a request from Silverlight application to a MVC and then return the result after a SQL query happens? I need to run a query that gets data from a database and returns a integer so the silverlight can display it. – DotNet Programmer Jun 17 '15 at 21:58
1

Do you have the Silverlight project added to your MVC project? If you don't you will need to go to your project that is your MVC, right click it and go to properties. Go to silverlight applications then add the project there too. Then try it with your current code in place and see if that works.