MvvmCross 5.3

Announcing MvvmCross 5.3!

A new MvvmCross version is available on NuGet! Most of our focus went out to creating new ViewPresenters for Xamarin.Forms and improving the code around that. With that said we are proud to announce these new ViewPresenters! If you have been using the default presenters we provide, you will find them very familiar. They work using the same view attributes system and are super flexible. But that is not everything. With MvvmCross 5.3, you will now be able to mix and match Native Xamarin views with Xamarin.Forms pages using ViewModel navigation!

Lets look at a sample view:

[MvxModalPresentation(WrapInNavigationPage = true, Title = "My Modal Page")]
public partial class MyModalViewPage : MvxContentPage<MyModalViewModel>
	public MyModalViewPage()

    // your code

Supported attributes

  • MvxContentPagePresentation
  • MvxMasterDetailPagePresentation
  • MvxModalPresentation
  • MvxNavigationPagePresentation
  • MvxTabbedPagePresentation
  • MvxCarouselPagePresentation

There are also new MvvmCross base classes for all Xamarin.Forms Page types supporting DataBinding, ViewModels and more from code and layout files!

To take advantage of all those new features make sure to use the Xamarin.Forms base classes for Setup, Appdelegate and others.

Extended MvvmCross bindings support

Already possible

<Label"Text ThisIsLocalized" />

New bindings

<Label Text="{mvx:MvxLang ThisIsLocalizedToo}" />
<Label Text="{mvx:MvxBind TextSource, Mode=OneTime, Converter=Language, ConverterParameter=ThisIsLocalizedThroughMvxBind}" />

Presenters improvements

To make the mixing for Xamarin.Forms and Native Xamarin views possible we had to align all the presenters. We’ve now done that and they use the same structure with View Attributes. At the same time we improved those presenters and fixed issues with Dialogs and the MvxNavigationService.

Breaking changes for presenters using view attributes

Now iOS, Android, macOS and WPF ViewPresenters implement an interface called IMvxAttributeViewPresenter, which is a common contract for all presenters using the view attributes system. As part of this refactoring, the dictionary that hosts the attribute types / show delegates has become a dictionary with two delegates: one for show, one for close. None of the behavior has changed, but since a few signatures have changed, if you are subclassing a presenter you will need to adjust your code. Please go straight to the presenter code if something doesn’t make sense, or ask us for help :).

Hooks for Fragments in Android

To get more control over your Fragment lifecycle - or Activity - and transitions, you can now override the folling methods (you can also modify your fragment transitions):

void OnFragmentChanged(FragmentTransaction ft, Fragment fragment, MvxFragmentPresentationAttribute attribute);

void OnFragmentChanging(FragmentTransaction ft, Fragment fragment, MvxFragmentPresentationAttribute attribute)

void OnFragmentPopped(FragmentTransaction ft, Fragment fragment, MvxFragmentPresentationAttribute attribute)

Android Activity transitions

In case you want to override the transition options between 2 activities you can override the folling method:

ActivityOptionsCompat CreateActivityTransitionOptions(Android.Content.Intent intent,MvxActivityPresentationAttribute attribute);

Open-Generic registration on IoC

There are situations where you have an interface with a generic type parameter IFoo<T> and you have to register it in the IoC Container with different T types. One way to do this is to register it as many times as T types you have:

Mvx.RegisterType<IFoo<Bar1>, Foo<Bar1>>();
Mvx.RegisterType<IFoo<Bar2>, Foo<Bar2>>();
Mvx.RegisterType<IFoo<Bar3>, Foo<Bar3>>();
Mvx.RegisterType<IFoo<Bar4>, Foo<Bar4>>();

But this creates boilerplate code and in case you need another instance with a different T type, you have to register it as well, which is error prone. To solve this situation, you can now register this interface as open-generic, i.e. you don’t specify the generic type parameter in neither the interface nor the implementation:

Mvx.RegisterType<IFoo<>, Foo<>>();

Then at the moment of resolving the interface the implementation takes the same generic type parameter that the interface, e.g. if you resolve var foo = Mvx.Resolve<IFoo<Bar1>>(); then foo will be of type Foo<Bar1>. As you can see this give us more flexibility and scalability because we can effortlessly change the generic type parameters at the moment of resolving the interface and we don’t need to add anything to register the interface with a new generic type parameter.

Change Log

5.3.0 (2017-10-13)

Full Changelog

Fixed bugs:

  • Pass MvxViewModelRequest.PresentationValues when navigating to Fragment on to it’s parent’s Activity when navigating #2237
  • Wrong host activity gets shown #2222
  • Close(this) is not working for Theme.Dialog on configuration change #1411
  • MvxWindowsViewPresenter swallowing exceptions thrown in Init #1309

Closed issues:

  • Make ViewAppeared and ViewAppearing return Task, for async purposes #2265
  • Unable to update nuget packages from version 5.1.1 to version 5.2.1 (ANDROID) #2253
  • [Android] Dialog doesn’t survive screen orientation change #2246
  • [Android] Dismissing dialog via back button doesn’t cancel Task #2245
  • Can’t install MvvmCross 5.2.1 in Xamarin Forms PCL Project #2240
  • OnStop needs a null check #2238
  • IMvxOverridePresentationAttribute not working of any Android view #2225
  • 2 Factor Login required for the MvvmCross organization from 22 September #2195
  • New nav service “deep link” conflict with viewmodel parameters when param is string #2080
  • MvxStringToTypeParser doesn’t support decimal. #1635
  • 4.5MB of MvxFragmentAttribute generated when starting up #1368
  • Parameterless Prepare() not called #2233
  • Feature Suggestion - Side by side Xamarin iOS/Android and Xamarin Forms #1889

Merged pull requests:

5.2.1 (2017-09-26)

Full Changelog

Fixed bugs:

  • Wrong ViewModel data in cached Fragment #1986
  • Binding in an MvxFragment is incorrectly resetting modified values #1264

Closed issues:

  • Exception in MvxAppCompatDialogFragment<T> #2220
  • Initialize is not called #2212
  • MvxNSSwitchOnTargetBinding appears in MvvmCross.Mac and MvvmCross.Binding.Mac #2205
  • WindowController from Storyboard (Mac) gets disposed #2198
  • Programmatically switching tabbed viewmodels from RootViewModel - Mac #2191
  • Where is that IFactory<T>? #2186
  • Hang when awaiting code in Initialize in 5.2 #2182
  • Support Toolbar and Unified Toolbar bindings by view for Mac #2180
  • Missing StarterPack for MvvmCross.Forms #2073
  • Wrong behavior on Move in MvxCollectionViewSourceAnimated #2061
  • Fragment viewmodel life-cycle events are not called if viewmodel has saved state and calling ShowViewModel<FragmentViewModel>(data) with data #1373

Merged pull requests: