-
Notifications
You must be signed in to change notification settings - Fork 2
MvvmCross Becomes the Leading MvvM Framework
Xamarin Forms is the View in the Model View ViewModel. To use Xamarin Forms you need an MvvM framework.
The Model View ViewModel Pattern was developed at Microsoft specifically to simplify event-driven programming of user interfaces—by exploiting features of Windows Presentation Foundation (WPF) (Microsoft's .NET graphics system) and Silverlight (WPF's Internet application derivative).
The above image file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
It shows the View and the ViewModel, essentially free standing components that are bound to each other via one way (either direction) or both way event subscriptions. Unlike a view with code behind, View and ViewModel are a complete separation of concerns and independance from the bindings. The ViewModel plays a similar role to the Controller in the Model View Controller pattern. View elements are bound to properties in the ViewModel. Buttons and other Action elements are bound to Commands in the ViewModel. These commands may load data for example in a search command or they may navigate to other ViewModels.
Data elements be they stored in a database or say Created, Retrieved, Updated and Deleted via a Restful web service or some other means form the Model. Typically there will be a set of data models each able to be encoded into a Class Object. The ViewModel will include these model classes in its own workings.
There are several MvvM Frameworks to choose between. The most comprehensive being MvvmCross.
MvvmCross
MvvmCross not only fully implements the MvvM Pattern it also has additional features that simplify coding Apps.
-
IoC Container you write an App that is activated by the native operating system. At some point though you need to call a service that is part of the Native operating system, e.g. to write to a file or to access the internet or to access geolocation services. This also includes code that you may customise for each Native Platform that you need to call from within a PCL. The problem here is the circular reference problem, that is solved via an IoC container. MvvMCross provides an IoC container, there are others including from Xamarin.
-
A Rich Library of Plugins Just about everything you may wish to do has been converted by an MvvMCross contributor into a Plugin. So rather than jumping in and doing that again, use a Plugin and become more productive. Examples of Plugins include the framework for platform support of SQLite, Sending a Text message, accessing HTML from a Web Site and decoding it into data etc.
-
And Much Much More the list is long, more later!
The Case Against MvvmCross
-
Steep Learning Curve and so many developers get started with something a lot simpler. In the end though their productivity will suffer.
-
MvvmCross was not Ready for Xamarin Forms for Six Months Part of the problem was the complexity of MvvmCross. Another issue is speed at which the environment is changing including additional platform targets, Universal windows Apps, Visual Studio 2015, Windows 10.
-
Lack of a Wiki Giving Simple How To Get Started Yes well MvvMCross relies on contributions from volunteers.
Enter Forms Presenters
For MvvmCross to work with Xamarin Forms we needed to develop a set of components called Forms Presenters. We reached this point about six months after the release of Xamarin Forms.
Then in order to make it easy for developers to fast track into MvvmCross Xamarin Forms we needed to develop a set of example solutions together with a Wiki that takes them through the technology example by example. The examples can then be cloned and adapted as a starting point for a solution.
This work is now under way.
Xamarin Forms and MvvMCross a Good Fit
Xamarin Forms and MvvMCross are a very good fit because they are both based on the MvvM pattern. Also because MvvMCross has a system of plugins, the requirement for 5% platform coding can be reduced further. Many common situations where you need to create platform specific code have already been solved via MvvMCross plugins. Examples:
- WebBrowser: access information off the Web available in HTML pages,
- Text Messaging: send a Text Message to a phone number
- SQLite: SQLite stores its data in a file but each native file system is different, additionally some targets already include SQLite as part of the operating system and some do not. The MvvMCross SQLite Plugin takes care of these interfacing issues so that you only need to be concerned about how you use SQLite in you PCL.