Dual-deploying a WPF app natively and as a XBAP

五迷三道 提交于 2019-12-04 16:56:11

You may want to take a look at Prism (at codeplex) It helps to target Wpf, Xbap and Silverlight with minimum code changes (the amount of extra work depends on your project).

Here's how to use it to create Wpf and Xbap application: Prism and XBap Applications

Eduardo Molteni

This scorbs article explain how to do it, and it even has an app template to do it.


(source: scorbs.com)

I have tried several approaches to this over the years. The one that has worked best for me is to have have four projects in a single solution:

  • The main project which builds a dll containing business objects, communications, and UI.
  • The test project containing both manual and automated unit tests
  • A tiny .exe project for the Windows application
  • A tiny .xbap project

In the main project there are neither Pages nor Windows, just UserControls and custom controls. There is also a services class for displaying UI. This class is subclassed in the Windows and XBAP projects to change the way things are displayed. In each case the subclass is installed in a static property as the application starts up. All the rest of the code simply references this static property and calls methods on it. These methods perform services which differ between Windows and XBAP applications.

For example, my service class has a "ShowDialog" method that takes a FrameworkElement and shows it in dialog style, either as a Window (for Windows application) or as a Popup on a page (for XBAP).

Using this technique has allowed for approximately 98% code sharing between the Windows application and the XBAP.

My main application also has a client-server interface defined and WCF attributes applied to its data objects. There is a static property used by all code to access the service. This static property is initialized (in the class constructor) to an instance of the concrete implementation class, but the startup code in the XBAP project replaces this with a WCF client, so the XBAP runs client-server and the Windows application is actually making local calls. In each case it is exactly the same object on the server end.

Because I implemented the WCF as an interface, I was able to get away with nothing more than a simple .svc file for the WCF service end of things, and no need for separate code generation or linking in proxy/stub code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!