Using the same ViewModel for a HTML and WPF view - wpf

It it possible to use the same ViewModel for a View implemented in C# (WPF) and a View in HTML ?
My goal is to be able to switch to a web View in the future, without rewriting everything.

Read about ASP.NET Core Blazor framework. Blazor allows you to mix C# code with HTML together, but it's not longer *.html format - the new format is called razor.

Related

Limitations of using WebBrowser control to create WPF apps [duplicate]

I've recently stumbled across WebBrowser WPF control. I am interested if there are any limitations when building user interfaces with HTML+CSS+JS and embedding them in WebBrowser.
So far I've successfully
intercepted HTML click events and handled them in C# using
[ComVisible(true)] class attribute
called JS script from C# using InvokeScript method.
InvokeScript also supports sending objects to the HTML/JS via parameters which faciliates two way communication.
Is there any reason for not using using WebBrowser to create simple apps? I am intersted in parts that absolutely need to be handled with some WPF code and cannot be bridged using WebBrowser.

Durandal Mobile Views

Does anyone have a solution that will allow you to create a desktop and mobile view for a single viewmodel in Durandal?
Ideally I would like to take a page from MVC4 and have a view.html and view.mobile.html for each viewmodel and just direct the browser to the relevant one based on userAgent string.
Edit 1
Looks like I can override the View Locator's convertModuleIdToViewId function, solution to follow.

IFrame on Silverllight

I want to add IFrame to my Silverlight web site. and into that iframe i want to add aspx page. is that possible? (aspx page in silverlight.)
It's posible in your HTML where you call the Silverlight xap file, but not inside Silverlight itself
Yes you can add what ever asp / html elements to the web page where your silverlight application is running.
For example modify the ProjectNameTestPage.aspx in your web project.
Actually it is possible to have HTML content nested within the Silverlight, Telerik for example has a control called "HtmlWindow" or "RadWindow" which does just this. Either you could subscribe to their control set or try and find out how they did it.
I have used Telerik's control multiple times in an MEF Silverlight application where different web applications (SSRS for example) are contained with the MEF plugins.

can we add silverlight application in tool box of asp.net web application

can we add silverlight application to tool box of asp.net web form application so that instead of writing HTML to include silverlight application i can just drag n drop it from tool box.
You can't add a silverlight app directly to the tool box. However its fairly simple to create a WebControl whose Render method writes out the appropriate <object> element with the source param pointing at your applications xap.
You can even add some properties from which that your render code could generate an initparams <param> element.
This WebControl would automatically end up in the ToolBox allowing you to drag it on the design surface.
You might even consider detecting that the control is rendering in the design time and change the output to display a reasonable placemarker for it in the designer.
Some versions ago Silverlight had a Silverlight Server control.
There is still one available here.

How to access web application class into silverlight application

I am beginner in silverlight..I have created a silverlight project. When a new silverlight project is created it is automatically creating a silverlight application and one web application. I have added a class in both applications. Now I want to access a method of web application class into silverlight application class. Is it possible? I have tried to add web application reference to silverlight but VS is not allowing. Is there any another way to do??
What you need is called WCF. A really simple tutorial that should get you going is found here: How to call WCF methods from Silverlight controls
Fundementally WCF allows the silverlight client to make method calls on a class instance hosted on the web site.
Yes it is possible, but not in the normal way. A Silverlight assembly can only reference another Silverlight assembly (this is a limitation of VS2008, i don't know if it has been changed in VS2010).
What you need to do is add an existing file to your Silverlight project, when the file browse dialog opens you navigate to the class file you want to reuse, but instead of just clicking the Add button, click on the little down arrow on the button and choose Add as link - now the file will "exist" in both projects and can be used in both.
If you are going to do this repeatedly though, you will want to move those shared class files out into a separate assembly, do a project reference from your web app, and have the equivalent Silverlight class library mirroring it (sharing the files as links), and then project reference that Silverlight class library from your Silverlight app.

Resources