Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM - Share/Reuse ViewModels between Silverlight and WPF

Is it possible to share viewmodels across platforms - WPF/Silverlight? I started down the path of putting my VMs in a separate assembly and soon came to ICommand - which then led me to ask this question? Is this possible, and if so is it good to do so? We have a possibility in the future of having a client application for WPF and Silverlight, so I would like to not have to duplicate VMs for both.

like image 465
justin coon Avatar asked Oct 11 '22 11:10

justin coon


1 Answers

You can potentially do this using the Portable Library Tools CTP. This allows you to target the full framework as well as Silverlight in a single library project.

Otherwise, it is possible, sort of. You still need two separate projects (for practical purposes), but can typically use a single source file. Have each project using the same source files keeps the reuse in place - but does require manual synchronization of the files. You can also add platform-specific functionality easily in this case via partial classes or defines, which does help to keep some of the workarounds for missing Silverlight functionality easy to maintain.

like image 180
Reed Copsey Avatar answered Jan 01 '23 11:01

Reed Copsey