首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FreshMVVM导航在离开模式页时抛出异常

FreshMVVM导航在离开模式页时抛出异常
EN

Stack Overflow用户
提问于 2020-01-13 03:20:44
回答 1查看 613关注 0票数 0

我正在使用一个LocalNotification插件(Nuget)生成一个电话通知事件,这是很好的工作。如果用户导航到一个列出通知并选择通知的页面,它将转到NotificationPageModel.cs页面。从那里,他们按一个按钮,导航他们离开,这工作,只要它是手动导航到。

如果用户单击电话的通知(app.xaml.cs:OnLocalNotificationTapped),那么当尝试导航时,它会生成一个FreshTinyIoC.TinyIoCResolutionException。

当用户单击通知(masterDetailNav.Navigation.PushModalAsync(npage);)时,如何从页面导航?

相关版本: Thudugala v4.0.5的Xamarin.Forms v3.6.0.264807 FreshMvvm v3.0.0 Plugin.LocalNotification

App.xaml.cs

代码语言:javascript
复制
void OnLocalNotificationTapped(NotificationTappedEventArgs e)
{
    var _logger = FreshMvvm.FreshIOC.Container.Resolve<ILoggingService>();
    _logger.Info("Pressed notification: {0}", e.Data);
    Notification notification = new Notification();
    if (string.IsNullOrWhiteSpace(e.Data))
    {
        return;
    }
    else
    {
        notification = JsonConvert.DeserializeObject<Notification>(e.Data);
    }

    //CoreMethods.PushPageModel<NotificationPageModel>(notification); //cant find coremethods
    var npage = FreshPageModelResolver.ResolvePageModel<NotificationPageModel>(notification);
    masterDetailNav.Navigation.PushModalAsync(npage);
}

NotificationPageModel.cs:

代码语言:javascript
复制
public async void Cancel()
{
    _logger.Info("Notification {0} Cancel: {1}", Notification.Gateway, Notification.TimeStamp);

    //Navigate away from page
    //await CoreMethods.PopPageModel(); //this only works if manually navigated to
    //attempt #1
    await CoreMethods.PushPageModel<HomePageModel>();
}

public async void Remove()
{
    _logger.Info("Notification {0} Remove: {1}", Notification.Gateway, Notification.TimeStamp);

    //Remove notification
    try
    {
        _user.Notifications.Remove(Notification);
    }
    catch (Exception ex)
    {
        _logger.Warn("Remove Notification: {0}", ex.Message);
    }

    //Navigate away from page
    //await CoreMethods.PopPageModel(); //this only works if manually navigated to
    //attempt #2
    var hpage = FreshPageModelResolver.ResolvePageModel<HomePageModel>();
    await CoreMethods.PushPageModelWithNewNavigation<HomePageModel>(hpage);
}

斯塔克迹

FreshTinyIoC.FreshTinyIoCContainer.ResolveInternal (FreshTinyIoC.FreshTinyIoCContainer+TypeRegistration注册,FreshTinyIoC.NamedParameterOverloads参数,FreshTinyIoC.ResolveOptions选项) 0x000f7 in C:\Projects\FreshMvvm\src\FreshIOC\FreshTinyIOC.cs:3142 at FreshTinyIoC.FreshTinyIoCContainer.Resolve (System.Type resolveType,( C:\Projects\FreshMvvm\src\FreshIOC\FreshTinyIOC.cs:1211 at FreshTinyIoC.FreshTinyIoCContainer.ResolveResolveType 0x00000 in C:\Projects\FreshMvvm\src\FreshIOC\FreshTinyIOC.cs:1332 at FreshMvvm.FreshTinyIOCBuiltIn.ResolveResolveType 0x00000 in C:\Projects\FreshMvvm\src\FreshMvvm\FreshTinyIOCBuiltIn.cs:31 at FreshMvvm.PageModelCoreMethods.PushNewNavigationServiceModal (FreshMvvm.IFreshNavigationService newNavigationService,FreshMvvm.FreshBasePageModel[] basePageModels,( C:\Projects\FreshMvvm\src\FreshMvvm\PageModelCoreMethods.cs:178 ) 0x00073 in FreshMvvm.PageModelCoreMethods.PushPageModelWithNewNavigationT 0x00060 in C:\Projects\FreshMvvm\src\FreshMvvm\PageModelCoreMethods.cs:235 at cdaxrobot.PageModels.NotificationPageModel.Go () 0x00225 in C:\Work\RobotApp\App\cdaxrobot\cdaxrobot\cdaxrobot\PageModels\NotificationPageModel.cs:113 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) 0x00000 in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Android.App.SyncContext+<>c__DisplayClass2_0.b__0 () 0x00000 in <11f101b564894ca7af6c482ddc51c698>:0 at Java.Lang.Thread+RunnableImplementor.Run () 0x00008 in <11f101b564894ca7af6c482ddc51c698>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv,(包装动态方法) Android.Runtime.DynamicMethodNameCounter.41(intptr,intptr)中的System.IntPtr native__this) 0x00009

EN

回答 1

Stack Overflow用户

发布于 2020-01-16 00:41:23

谢谢你的回应。我通过创建一个新的NavigationContainer来修复它:

代码语言:javascript
复制
notificationPage = FreshMvvm.FreshPageModelResolver.ResolvePageModel<NotificationPageModel>(true);
notificationContainer = new FreshNavigationContainer(notificationPage, Models.Constants.NotificationContainer);

void OnLocalNotificationTapped(NotificationTappedEventArgs e)
{
    MainPage = notificationContainer;
}

然后在这一页里我做了这样的事情:

代码语言:javascript
复制
if (CameFromNotification == true)
{
    _logger.Debug("Navigating back to MainContainer");
    CoreMethods.SwitchOutRootNavigation(Models.Constants.MainContainer);
}
else
{
    _logger.Debug("Navigating by popping the stack");
    await CoreMethods.PopPageModel();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59710226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档