0

I have a WPF app targeting .NET 4 which I am updating and maintaining for a customer. In the course of the project, we have also ported the functionality to a Xamarin mobile app.

I was able to improve some of the model classes and other back end classes in order to directly port them to the Xamarin app, but the WPF app had a lot of business code nested into its view. At the time, I didn't have time to factor it out into the ViewModel, but now I have created the Xamarin app with a much better separation between View and ViewModel. I am hoping to translate some of the nicer separated ViewModel code back into the WPF desktop app for the sake of even better code sharing and less redundancy. However, in the Xamarin app I am using Xamarin.Forms.MessagingCenter to send statuses back to the user and display modal popups.

So with all of the preamble, my question is this: What is a better messaging mechanism that I can utilize in both my Xamarin app and my WPF app to make my ViewModel more portable? With the exception of an MVVM framework that works in both environments like Prism, what are my options? The only one I can think of is using native c# events, but that's why I'm here in case I'm missing a better alternative. Thanks!

  • 1
    Can't you use the same Xamarin.Forms.MessagingCenter library for Windows? – Emerson Cardoso Dec 12 '17 at 16:07
  • @EmersonCardoso: Possibly, if it doesn't require .NET Core. .NET Core has some rather severe limitations on Windows. WPF won't run at all on it. – Robert Harvey Dec 12 '17 at 16:11
  • @StephenH: The moral equivalent of an Event in WPF is something that implements the ICommand interface, like a RelayCommand or CompositeCommand. – Robert Harvey Dec 12 '17 at 16:13
  • The MVVM Light toolkit has the Messenger class which pretty much does the same thing - I think it works with both WPF and Xamarin. (link) – Filip Milovanović Dec 13 '17 at 0:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.