Xamarin.forms FreshMVVM导航在离开模式页面时引发异常
我正在使用LocalNotification插件(nuget)生成手机 事件通知,效果良好。如果用户导航到 一个列出通知并选择一个的页面,它会转到 NotificationPageModel.cs页面。从那里他们按下一个按钮 将其导航到别处,只要手动导航即可 对 如果用户单击手机的通知 (app.xaml.cs:onLocalNotification点击)然后在尝试导航时 离开后,它会生成一个FreshTinyIoC.TinyIoCResolutionException 当用户单击页面时,我如何离开页面 通知(Xamarin.forms FreshMVVM导航在离开模式页面时引发异常,xamarin.forms,notifications,freshmvvm,Xamarin.forms,Notifications,Freshmvvm,我正在使用LocalNotification插件(nuget)生成手机 事件通知,效果良好。如果用户导航到 一个列出通知并选择一个的页面,它会转到 NotificationPageModel.cs页面。从那里他们按下一个按钮 将其导航到别处,只要手动导航即可 对 如果用户单击手机的通知 (app.xaml.cs:onLocalNotification点击)然后在尝试导航时 离开后,它会生成一个FreshTinyIoC.TinyIoCResolutionException 当用户单击页面时,我如何
masterDetailNav.Navigation.PushModalAsync(npage);
)
相关版本:Xamarin.Forms v3.6.0.264807 FreshMvvm v3.0.0
Plugin.LocalNotification by Thudugala v4.0.5
App.xaml.cs
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);
}
void onlocalnotification点击(NotificationTappedEventArgs e)
{
var_logger=FreshMvvm.FreshIOC.Container.Resolve();
_Info(“按下通知:{0}”,e.Data);
通知通知=新通知();
if(string.IsNullOrWhiteSpace(e.Data))
{
返回;
}
其他的
{
notification=JsonConvert.DeserializeObject(如数据);
}
//PushPageModel(通知);//找不到CoreMethods
var npage=FreshPageModelResolver.ResolvePageModel(通知);
masterDetailNav.Navigation.PushModalAsync(npage);
}
NotificationPageModel.cs:
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);
}
public async void Cancel()
{
_logger.Info(“通知{0}取消:{1}”,通知.Gateway,通知.TimeStamp);
//离开页面导航
//wait CoreMethods.PopPageModel();//仅当手动导航到
//尝试#1
等待corethods.PushPageModel();
}
公共异步void Remove()
{
_Info(“通知{0}删除:{1}”、通知.Gateway、通知.TimeStamp);
//删除通知
尝试
{
_user.Notifications.Remove(通知);
}
捕获(例外情况除外)
{
_Warn(“删除通知:{0}”,例如Message);
}
//离开页面导航
//wait CoreMethods.PopPageModel();//仅当手动导航到
//尝试#2
var hpage=FreshPageModelResolver.ResolvePageModel();
等待CoreMethods.PushPageModelWithNewNavigation(hpage);
}
堆栈跟踪
FreshTinyIoC.TinyIoCResolutionException消息=解析失败:
IFreshNavigationService Source=mscorlib StackTrace:at
FreshTinyIoC.FreshTinyIoCContainer.ResolveInternal
(FreshTinyIoC.FreshTinyIoC容器+类型注册,
FreshTinyIoC.NamedParameters重载参数,
中的FreshTinyIoC.ResolveOptions选项)[0x000f7]
C:\Projects\FreshMvvm\src\FreshIOC\FreshTinyIOC.cs:3142 at
FreshTinyIoC.FreshTinyIoCContainer.Resolve(System.Type resolveType,
中的System.String名称)[0x00000]
C:\Projects\FreshMvvm\src\FreshIOC\FreshTinyIOC.cs:1211 at
FreshTinyIoC.FreshTinyIoCContainer.Resolve[ResolveType](System.String)
中的名称)[0x00000]
C:\Projects\FreshMvvm\src\FreshIOC\FreshTinyIOC.cs:1332 at
FreshMvvm.FreshTinyIOCBuiltIn.Resolve[ResolveType](System.String)
中的名称)[0x00000]
C:\Projects\FreshMvvm\src\FreshMvvm\FreshTinyIOCBuiltIn.cs:31 at
FreshMvvm.PageModelCoreMethods.PushNewNavigationServiceModel
(FreshMvvm.IFreshNavigationService新导航服务,
FreshMvvm.FreshBasePageModel[]basePageModels,System.Boolean动画)
[0x00073]英寸
C:\Projects\FreshMvvm\src\FreshMvvm\PageModelCoreMethods.cs:178 at
FreshMvvm.PageModelCoreMethods.PushPageModelWithNewNavigation[T]
(System.Object数据,System.Boolean动画)[0x00060]英寸
C:\Projects\FreshMvvm\src\FreshMvvm\PageModelCoreMethods.cs:235 at
cdaxrobot.PageModels.NotificationPageModel.Go()[0x00225]位于
C:\Work\RobotApp\App\cdaxrobot\cdaxrobot\cdaxrobot\PageModels\NotificationPageModel.cs:113
在
System.Runtime.CompilerServices.AsyncMethodBuilderCore+c.b\u 7\u 0
中的(System.Object状态)[0x00000]
/Users/builder/jenkins/workspace/archive mono/2019-08/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/asynchmethodbuilder.cs:1021
在Android.App.SyncContext+c_uuuu显示Class2_0.b_uu0()
[0x00000]英寸:0英寸
中的Java.Lang.Thread+RunnableImplementor.Run()[0x00008]
:0 at
Java.Lang.IRunnableInvoker.n_运行(System.IntPtr jnienv,System.IntPtr
本机\uuu此[0x00009]位于:0处
(包装器动态方法)
Android.Runtime.DynamicMethodNameCounter.41(intptr,intptr)
谢谢你的回复。 我通过创建一个新的NavigationContainer来修复它:
notificationPage = FreshMvvm.FreshPageModelResolver.ResolvePageModel<NotificationPageModel>(true);
notificationContainer = new FreshNavigationContainer(notificationPage, Models.Constants.NotificationContainer);
void OnLocalNotificationTapped(NotificationTappedEventArgs e)
{
MainPage = notificationContainer;
}
如果在
NavigationStack
中推送一个ModalPage,并希望弹出该页面,则应使用CoreMethods
中的PopPageModel
方法,然后传递一个布尔值作为参数,通知Pop方法它是一个模式页面。PopPageModel
有两个覆盖,其中该参数分别为第一个和第二个。FMI:
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();
}