How to reuse Silverlight projects in WPF?
I would like to use the same project (class library) in Silverlight and WPF. So, I started as a Silverlight Class Library.
But the problem is: some of the common classes (i.e. Point, TouchAction) exists in different assemblies and c开发者_StackOverflowompiler is showing the following error when I add the reference of Silverlight class library to WPF project.
The type 'System.Windows.Point' exists in both 'c:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll' and 'C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\WindowsBase.dll'
Can anyone please suggest a work around?
You can try Prism 2.0 approach:
Have two sepparated projects, but link files from one to another. Pieces that are specific to one platform can be sepparated in conditional compilation (#ifdef _SILVERLIGHT ... #elseif ... #end)
Check out the Multitargeting quickstart for more details (though all Quickstarts plus the Reference Implementation have Silverlight & WPF versions, the multitargeting sample is the simpliest one if you only want to share code between platforms). In the same project, you'll find the Project Linker tool (though it only works in VS2008 as far as I know) which automatically keeps two or more projects synced-up by adding links automatically when new items are added to the source project.
Hope this helps!
精彩评论