I struggle to understand difference between mvvm fresh & mvvm light, Or I can say I am just jumping into it. So anybody just shed a light on it to be comfort to use it with xamarin.forms application.
I have used FreshMVVM in couple of mobile apps for both Small and Tablet devices. FreshMvvm is very light yet still gives you all the features you need and it is specifically designed to work on Xamarin Forms. It adds extra parts to existing Xamarin Forms capabilities like :
ViewModel Navigation
IOC
Automatic Wiring of ViewModels and Page events like (Appearing, Disappearing etc.)
It gives you the functionalities like Init and ReverseInit
It has built in Dialog service (alerts)
It supports Simple navigation, MasterDetail navigation and Tabbed Navigation
The Naming Conventions used are simple
It is very light and easy to implement
They have a very nice reference and detailed information in their project site.
https://github.com/rid00z/FreshMvvm
Update : What about MvvmLight?
All of these frameworks provides common features. Because the goal of all of them is same - providing cross platform tools that would support all of the above features I listed for FreshMvvm. The only differences however may be some of them might have some more features included and the way of implementing their Base Classes.
Recommendation for you : You should learn FreshMvvm (more light and easy to learn) and MvvmCross. These 2 are the current popular ones for Xamarin and Xamarin Forms platform.
Related
While creating app in Xamarin Forms using Mvvm and MvvmLight, couldn't find significant reason of using MvvmLight. As all the features are already being provided by the xamarin forms/.net.
So if someone could point out the significance of MvvmLight (maybe with an example)?
This is probably just what people are used to using with WPF. Instead of re-learning the terminology of Xamarin.Forms Mvvm they stick with Mvvmlight.
There are probably other reasons. Mvvmlight focus solely on Mvvm where as Xamarin.Forms resources are more spread out so may not adapt to design pattern changes as quickly as MvvmLight.
If I were choosing an Mvvm library to use I would choose MvvmLight for the reasons stated above
I have been using MVVM light for some time, the one thing I love is that You can make UI changes to datatemplates during design time.
I am still new to Xamarin MVVM, but from what I can tell you have no design time preview in the shared project(Xamarin Forms) yet.
So MVVM light may not give you such an advantage.
Questions to ask yourself is why you would need an MVVM library in the first place.
I am looking into potentially using Caliburn Micro for an upcoming Windows Phone and Windows RT application and I'm wondering if it's possible, or advisable, to reuse view models across both platforms?
I have seen examples using Portable Libraries and in another framework called MvvmCross, but I'm not sure if I could do this using Caliburn because I can't add Caliburn to a Portable Library and therefore can't share interfaces, such as INavigationService, with view models sitting in the shared portable library.
I am thinking of simply having one set of view models for Windows Phone and another for WinRT.
Any ideas on how to proceed?
As an experiment I took parts of CM and made it portable so my view models could live in a portable. I mainly wanted to take advantage of screens and conductors in a portable and only have one set of view models.
The creator of CM has mentioned making CM 2.0 support portables but it will be a decent amount of work.
I've experimented with MvvmCross and the v3 stuff is really slick even if you're not targeting iOS or Android.
So, for CM, the only option with the current version is to have separate view models for WinRT and WP.
I've decided to dabble a bit in MonoDroid and MonoTouch and port one of my WP7 apps as a starter. I would really like to reuse my existing ViewModels but since both Android and iOS seem to have no such thing as XAML's strong databinding I would like to ask if anyone went that route before and can recommend some best practices or existing solutions.
We're doing this with an application right now, but writing for iOS first (even before Windows). It is not full of rainbows and ponies for sure.
I would recommend the following:
Use a MVVM framework on Windows that doesn't require you to expose ICommand on every action the user takes (like Caliburn, for example), it also shouldn't require a dependency to it from within all of your ViewModels.
Conditionally inherit the WPF-specific pieces of your ViewModelBase class, you can do this with partial classes or an #if iPhone directive. INotifyPropertyChanged or ICommand are examples.
Use an IoC container, it is very helpful to abstract out things like saving settings to the filesystem which will be very different on all platforms. Also helps to sort out your dependencies as well, which is very helpful for separating out platform-specific code from non-platform specific.
Use a "messenger" of some kind (example here), usually included with an MVVM framework. This is a must in my opinion, at least for iOS. Apple's MVC is so all over the place, it's better to have global messages you can subscribe to in a weak referenced (and decoupled) way.
Use MVC on each platform like you would natively, then treat each ViewModel as you would if you were calling it manually. There are no UI bindings, no ICommand, so keep your ViewModel's simple.
Linking files is the best trick ever. You don't want a copy of each view model per platform, so make sure you know how to link to a file within projects in Visual Studio and MonoDevelop. This also makes #if iPhone and #if Android statements possible.
I know you are working with an existing application, so it's tough. It may be simpler to just reuse your business model and that's it. Android and iOS have MVC patterns of their own, and are drastically different from WPF. You might also only need a subset of each ViewModel on mobile devices, which could make it easier to just rewrite.
In our case:
We're using TinyIoC (also has it's own messenger)
We will use Caliburn-Micro when we start on WPF, we don't need some of the features in full Caliburn
I've recently finished a large project which we wrote wp7 first, and which was then ported into touch and droid.
As part of this we've released our own mvvm framework - including some databinding support for touch and droid - the source is available at http://github.com/slodge/mvvmcross
The experience of porting to droid was good - the axml layout files provided a good hook for databinding. Currently, however, i'm not quite as happy with the binding we achieved for touch - although montouch.dialog does at least provide us with some nice looking code sometimes.
I have to create now a multi-screen Silverlight 4 RIA application with MVVM.
Each of these screens has to be devided in multiple regions (for example master-detail scenario whereas each of them is a different section and one has control on the other).
Can you give me some ideas what should be the right way to implement such an application?
Is Prism the right choice? I started reading the Prism manual and liked very much the idea of having regions and screens switched and controls in a very flexible manner, but, as said above, I find it too overkill to split it all over many assemblies.
If Prism IS the right choice, then I would appreciate any kind of guidance or reference to guidance on this particular scenario (multiple screens & regions and OTOH not getting my solution spotted with a gazillion projects.
I believe that PRISM is the correct choice for building an application with multiple regions and views. You could argue that that is almost the definition of a composite application.
But I would also remember that you don't have to use all the components PRISM has, you can pick and choose. I would recommend that you consider each aspect of PRISM and test/prototype to ensure you are happy with the facilties offered. In a large application I have built I use PRISM but after some prototype investigations I only used EventAggregator and the Modularity capabilities.
I chose not to use the region support as I found working with ItemControl and ContentControl components in Silverlight gave me the ability to inject views and partial views into my interface.
I found experience from ASP.NET MVC proved useful in considering how to coordinate/break up my UI into partial views.
Hope that helps. The Stocktrader application is a great example to learn from (included with the PRISM distributable).
Any good sample WP7 application using MVVM model in the optimal way?
I'm creating my first WP7 app, and I'm using MVVM as far as I can tell, but I'm not sure I'm doing it the right way. I have one view model per page, instead of one main view model that branches to each page, I'm not sure which is the correct way to do, so I'm hoping there's a sample app out there that I can check out.
Thanks!
Edit: I'm also having another problem on saving the ViewModels in the application state, because I think they have to be serializable (haven't worked much into this), the thing is that when I start a task and come back to the app, the latter has already been deactivated by calling the former, so I have to serialize its state when deactivated and [re]serialize it when [re]activated. This is how I save the state when deactivated:
object[] viewModels = new object[3];
viewModels[0] = App.ViewModelPage1;
viewModels[1] = App.ViewModelPage2;
viewModels[2] = App.ViewModePage3;
PhoneApplicationService.Current.State.Add("LastState", viewModels);
Again, this is probably not efficient way to do it, so I'm hoping I can see a sample app that handles this well too.
Thanks!
Have you looked at using the MVVM Light toolkit?
Serialization best practices will vary based on the volume of data in the model, the number of models being used and whether it's necessary to always load all of the models.
You might want to check out Caliburn Micro. It is used to implement a number of user experience patterns but it supports WP7 and has sample code.
Here's some MVVM samples and guidance you can check out.
C#er : IMage: Model-View-ViewModel (MVVM) Explained
.NET by Example: Using MVVM Light to drive a Windows Phone 7 / Silverlight 4 map viewer
The simplest way to do design-time ViewModels with MVVM and Blend.
Also an overview here of MVVM frameworks you may find worth a look.
JAPF » Blog Archive » Discover and compare existing MVVM frameworks
Light weight seems to be good and MVVM Light is popular. Laurent demos MVVM in the Mix 10 video EX14 if you want to check that out too.
This months MSDN magazine has an article on creating a WP7 Sudoko app using MVVM.
http://msdn.microsoft.com/en-us/magazine/gg490347.aspx
HTH
Here is my article which describes the approach to build WP7 applications using advantages of separation of concerns:
a framework for building of WP7 application