Forum Xamarin.Mac

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to share View Models between targeting MacOS and other Xamarin Forms target platforms

I'd like to be able to share view models between the recommended native MacOS target and other targets in a .NET Standard library.
MVVM isn't necessary as long as I can implement data binding in the MVC MacOS native style from the storyboard views and share the common platform independent view models.
I'd also like to avoid changing the other Xamarin Forms targets to use a 3rd party framework like MVVMLite or MVVMCross.
I'd also like to use .NET Standard for my view model library rather than PCL with conditional compilation. Is there a way to avoid using a MacOS specific base type in my view models.

How do you recommend this be done without having the common view models depend on the MacOS types or duplicating the properties in the MacOS version?

Posts

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    The requirement to have NSObject base types when you are using Cocoa data binding techniques can be painful. I've seen some people use defines and different projects but the same source code to hack around this.

    I don't know of any amazing solutions here. Apple really doesn't help us much here.

  • Hi Chris,
    Thanks for your suggestion. I considered doing that but wanted to use .NET Stanrd rather the PCL libs. I also thought about defining and interface for my view models and either generating a wrapper class that derived from nsobject and uses depency injection to pass in a view model instance and the implements the interface and delegates to my view model. These kinds of things would come from the Xamarin team rather than Apple since Apple won’t eliminate the need for deriving from NSObject. There are also possible 3rd party frameworks like amVVMCross and MVVMLite that do MVVM but I didn’t want to oolute my view models. Also Xamarin has a partial implementation for Xamarin Forms targeting MacOS but the progress seems stale and it isn’t mentioned in their roadmap for Xararin Forms and I am not able to get and answer from a xamarin on an estimated release date or priority of it and there is still a lot to finish there.
Sign In or Register to comment.