Closed opcodewriter closed 8 years ago
I think I found it:
https://github.com/aspnetde/MvvmNano/blob/master/src/MvvmNano.Forms/MvvmNanoApplication.cs#L56
It's casting MainPage
which is a MvvmNanoTabbedPage
to .CreateViewFor<TViewModel> () as MvvmNanoContentPage<TViewModel>
and the result is null`.
Is MvvmNanoTabbedPage
an incomplete implementation? Or maybe I'm just missing something.
Moreover, how is MvvmNanoTabbedPage
supposed to work anyway? Since the pages inside the TabbedPage
are not created though the usual NavigateTo
, their view-models can't be created trough the current flow so to speak.
Or maybe presenter needs to be changed to create and set view-models for each page of the TabbedPage
? I think this would work.
Issue is I don't see a fast workaround for now... I wasn't expecting to bump into this one
If you have a MvvmNanoTabbedPage
called LandingPage
, here is the XAML for it that contains 4 sub pages.
<?xml version="1.0" encoding="utf-8" ?>
<pages:MvvmNanoTabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyAssembly;assembly=MyAssembly"
xmlns:vm="clr-namespace:MyAssembly.ViewModels"
xmlns:pages="clr-namespace:MvvmNano.Forms"
x:Class="MyAssembly.LandingPage"
x:TypeArguments="vm:LandingViewModel"
Title="3in1 NextGen">
<local:HomePage>
<x:Arguments>
<vm:HomeViewModel/>
</x:Arguments>
</local:HomePage>
<local:ProgressPage>
<x:Arguments>
<vm:ProgressViewModel/>
</x:Arguments>
</local:ProgressPage>
<local:CompletedPage>
<x:Arguments>
<vm:CompletedViewModel/>
</x:Arguments>
</local:CompletedPage>
<local:SettingsPage>
<x:Arguments>
<vm:SettingsViewModel/>
</x:Arguments>
</local:SettingsPage>
</pages:MvvmNanoTabbedPage>
Then for each of your MvvmNanoContentPage
pages that you are adding to the TabbedPage you have to add a new constructor so you can manually set the ViewModel.
public partial class HomePage : MvvmNanoContentPage<HomeViewModel>
{
//add new constructor here
public HomePage(HomeViewModel model)
{
SetViewModel(model);
InitializeComponent();
}
public HomePage()
{
InitializeComponent();
}
}
public partial class ProgressPage : MvvmNanoContentPage<ProgressViewModel>
{
//add new constructor here
public ProgressPage(ProgressViewModel model)
{
SetViewModel(model);
InitializeComponent();
}
public ProgressPage()
{
InitializeComponent();
}
}
public partial class HomePage : MvvmNanoContentPage<CompletedViewModel>
{
//add new constructor here
public CompletedPage(CompletedViewModel model)
{
SetViewModel(model);
InitializeComponent();
}
public CompletedPage()
{
InitializeComponent();
}
}
public partial class SettingsPage : MvvmNanoContentPage<SettingsViewModel>
{
//add new constructor here
public SettingsPage(SettingsViewModel model)
{
SetViewModel(model);
InitializeComponent();
}
public ProgressPage()
{
InitializeComponent();
}
}
Any example of using it?
I have an XAML like the following
and I am getting: