When I create a new Xamarin.Forms application using the Prism template pack the project gets created with a MainPageViewModel
that inherits from ViewModelBase
Later I create and an additional View and ViewModel say for ChatPage. This ChatPageViewModel
inherits from BindableBase
not ViewModelBase
as generated by the Add New dialog.
I'd like to use ViewModelBase in all my View(Models) ViewModelBase inherits from ViewModelBase : BindableBase, INavigationAware, IDestructible
I try and change the new ChatPageViewModel : BindableBase
to ChatPageViewModel : ViewModelBase
but the constructor gets a red squiggly error;
Error CS7036 There is no argument given that corresponds to the required formal parameter 'navigationService' of 'ViewModelBase.ViewModelBase(INavigationService)'
I see in App.xaml.cs that containerRegistry.RegisterForNavigation<NavigationPage>();
is implemented differently than the other pages containerRegistry.RegisterForNavigation<ChatPage, ChatPageViewModel>();
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>();
containerRegistry.RegisterForNavigation<SettingsPage, SettingsPageViewModel>();
containerRegistry.RegisterForNavigation<ChatPage, ChatPageViewModel>();
containerRegistry.RegisterSingleton<IXpdSettings, XpdSettings>();
containerRegistry.RegisterSingleton<IMqttDataService, MqttDataService>();
}
Is there a way I can inherit from ViewModelBase? Could / should it be implemented in the XamarinForms Prism templating?