MvvmCross-Wpf CustomPresenter

MvvmCross-Wpf CustomPresenter,wpf,mvvmcross,Wpf,Mvvmcross,我试图使用MvxWpfViewPresenter从一个视图导航到另一个视图,但在尝试使用IMVxWPFviewContainer呈现它时遇到了一些问题 我已在App.Xaml.Mvx.cs中注册了IMvxWpfViewsContainer,并将我的ViewModel添加到其中 private void DoSetup() { LoadMvxAssemblyResources(); var presenter = new MvxWpfPresenter(MainWindow);

我试图使用MvxWpfViewPresenter从一个视图导航到另一个视图,但在尝试使用IMVxWPFviewContainer呈现它时遇到了一些问题

我已在App.Xaml.Mvx.cs中注册了IMvxWpfViewsContainer,并将我的ViewModel添加到其中

private void DoSetup()
{
    LoadMvxAssemblyResources();

    var presenter = new MvxWpfPresenter(MainWindow);

    var setup = new Setup(Dispatcher, presenter);
    setup.Initialize();

    Mvx.RegisterType<IMvxWpfViewsContainer, MvxWpfViewsContainer>();
    var viewContainer = Mvx.Resolve<IMvxWpfViewsContainer>();
    viewContainer.Add<MyViewModel, MyView>(); //Adding my view to the IMvxWpfViewsContainer

    var start = Mvx.Resolve<IMvxAppStart>();
    start.Start();

    _setupComplete = true;
}
我是用错误的方式注册的还是我忘记了什么

堆栈是:

at Cirrious.MvvmCross.Views.MvxViewsContainer.GetViewType(Type viewModelType)
at Cirrious.MvvmCross.Wpf.Views.MvxWpfViewsContainer.CreateView(MvxViewModelRequest request)
at MySolution.MvxWpfPresenter.ChangePresentation(MvxPresentationHint hint) in **MYPATH**\MvxWpfPresenter.cs:line 32
at Cirrious.MvvmCross.Wpf.Views.MvxWpfViewDispatcher.<>c__DisplayClass4.<ChangePresentation>b__3()
at Cirrious.CrossCore.Core.MvxMainThreadDispatcher.ExceptionMaskedAction(Action action)
位于cirriary.MvvmCross.Views.MvxViewsContainer.GetViewType(类型viewModelType)
在cirriary.MvvmCross.Wpf.Views.MvxWpfViewsContainer.CreateView(MvxViewModelRequest请求)中
在**MYPATH**\MvxWpfPresenter.cs:32行中的MySolution.MvxWpfPresenter.ChangePresentation(MvxPresentationHint提示)处
在Cirrious.MvvmCross.Wpf.Views.MvxWpfViewDispatcher.c_udisplayClass4.b_u3()中
在cirrium.CrossCore.Core.MvxMainThreadDispatcher.ExceptionMaskedAction(操作)

我在代码中找到了问题所在。如果有人有同样的问题,我会把答案贴在这里

当我注册IMvxWpfViewsContainer时,我只是在注册它。相反,我不得不把它注册为单身汉

因此,解决方案是修改以下代码:

Mvx.RegisterType<IMvxWpfViewsContainer, MvxWpfViewsContainer>();
Mvx.RegisterType();
致:

Mvx.RegisterSingleton(()=>newmvxwpfviewscontainer());

您是否可以编辑问题以添加有关异常的更多详细信息?例如,是否存在stacktrace?我已将堆栈添加到问题中,很抱歉忘记刚刚发现错误,将发布Herdaniel,您是否可以进一步说明您的设置?我不确定如何使用ViewsContainer。您应该在演示者中使用它,如上所示。您可以在设置“viewContainer.Add()”中向其注册视图/视图模型,并在视图演示器中创建requesttranslator,如上所示,以创建视图模型的视图。我不知道怎么说得更清楚,因为我不知道你不明白什么。如果可以的话,用你的疑问创造一个问题,这样我或其他人就可以回答
at Cirrious.MvvmCross.Views.MvxViewsContainer.GetViewType(Type viewModelType)
at Cirrious.MvvmCross.Wpf.Views.MvxWpfViewsContainer.CreateView(MvxViewModelRequest request)
at MySolution.MvxWpfPresenter.ChangePresentation(MvxPresentationHint hint) in **MYPATH**\MvxWpfPresenter.cs:line 32
at Cirrious.MvvmCross.Wpf.Views.MvxWpfViewDispatcher.<>c__DisplayClass4.<ChangePresentation>b__3()
at Cirrious.CrossCore.Core.MvxMainThreadDispatcher.ExceptionMaskedAction(Action action)
Mvx.RegisterType<IMvxWpfViewsContainer, MvxWpfViewsContainer>();
Mvx.RegisterSingleton<IMvxWpfViewsContainer>(() => new MvxWpfViewsContainer());