Xamarin.forms Prism继承自ViewModelBase与BindableBase

Xamarin.forms Prism继承自ViewModelBase与BindableBase,xamarin.forms,prism,Xamarin.forms,Prism,当我使用Prism模板包创建一个新的Xamarin.Forms应用程序时,该项目将使用继承自ViewModelBase 稍后,我创建了一个附加的视图和ViewModel,比如ChatPage。此ChatPageViewModel继承自添加新对话框生成的BindableBase而非ViewModelBase 我想在所有视图(模型)中使用ViewModelBase ViewModelBase继承自ViewModelBase:BindableBase、INavigationAware、Idestruc

当我使用Prism模板包创建一个新的Xamarin.Forms应用程序时,该项目将使用继承自
ViewModelBase

稍后,我创建了一个附加的视图和ViewModel,比如ChatPage。此
ChatPageViewModel
继承自添加新对话框生成的
BindableBase
而非
ViewModelBase

我想在所有视图(模型)中使用ViewModelBase ViewModelBase继承自
ViewModelBase:BindableBase、INavigationAware、Idestructable

我尝试将新的
ChatPageViewModel:BindableBase
更改为
ChatPageViewModel:ViewModelBase
,但构造函数得到一个红色的扭曲错误; 错误CS7036未给出与“ViewModelBase.ViewModelBase(INavigationService)”的必需形式参数“navigationService”对应的参数

我在App.xaml.cs中看到
containerRegistry.RegisterForNavigation()的实现方式不同于其他页面
containerRegistry.RegisterBonNavigation()

受保护的覆盖无效注册表类型(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterSingleton();
containerRegistry.RegisterSingleton();
}

有没有一种方法可以从ViewModelBase继承?是否可以/应该在XamarinForms Prism模板中实现它?

答案包含在我的问题中。请参阅MainPageViewModel(由初始项目创建对话框创建)使用的语法-其中MainPageViewModel继承自ViewModelBase,而不是使用从BindableBase继承的添加新对话框创建的后续页面。例如,ChatPageViewModel继承自ViewModelBase而非BindableBase

public class ChatPageViewModel : ViewModelBase 
{
    private IXpdSettings _xpdsettings;
    public ChatPageViewModel(INavigationService navigationService, IXpdSettings xpdSettings)
        : base(navigationService)
    {
        Title = "Mqtt Chat";
        _xpdsettings = xpdSettings;
    }
}

答案在我的问题中。请参阅MainPageViewModel(由初始项目创建对话框创建)使用的语法-其中MainPageViewModel继承自ViewModelBase,而不是使用从BindableBase继承的添加新对话框创建的后续页面。例如,ChatPageViewModel继承自ViewModelBase而非BindableBase

public class ChatPageViewModel : ViewModelBase 
{
    private IXpdSettings _xpdsettings;
    public ChatPageViewModel(INavigationService navigationService, IXpdSettings xpdSettings)
        : base(navigationService)
    {
        Title = "Mqtt Chat";
        _xpdsettings = xpdSettings;
    }
}

那么您想在Visual studio中创建一个模板,使
ViewModelBase
成为您创建的基类视图模型?那么您想在Visual studio中创建一个模板,使
ViewModelBase
成为您创建的基类视图模型?