【问题标题】:Xamarin forms : Issues with xamarin popup imageXamarin 表单:xamarin 弹出图像的问题
【发布时间】:2018-07-11 10:14:12
【问题描述】:

我正在使用 Rg.Plugins.Popup Nuget 来显示一个弹出窗口。我的疑问是如何从 viewmodel 类中调用弹出页面?我在 viewmodel 中使用以下代码。

  var page = new Pages.MyPopUpImage();
  await PopupNavigation.Instance.PushAsync(page);

运行项目时出现 MissingMethodException。也不能在 xaml.cs 类中工作,在那里得到相同的异常。

[0:] Exception:>>System.MissingMethodException: Method 'Xamarin.Forms.Platform.Android.Platform.CreateRendererWithContext' not found.
at Rg.Plugins.Popup.Droid.Impl.PopupPlatformDroid+<AddAsync>d__11.MoveNext () [0x0002c] in C:\projects\rg-plugins-popup\src\Rg.Plugins.Popup.Droid\Impl\PopupPlatformDroid.cs:45 
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
at Rg.Plugins.Popup.Services.PopupNavigationImpl+<AddAsync>d__11.MoveNext () [0x00039] in C:\projects\rg-plugins-popup\src\Rg.Plugins.Popup\Services\PopupNavigationImpl.cs:111 

提前致谢

【问题讨论】:

    标签: xamarin.forms popup


    【解决方案1】:
    .. how can I call a popuppage from viewmodel class?
    

    一种选择是将Navigation 从您的Page 传递给ViewModel。有多种方法可以做到这一点,一种快速而肮脏的方法是例如通过构造函数传递它,然后很容易打开一个弹出窗口:

    await Navigation.PushPopupAsync(new MyPopUpPage());
    

    P.S.:System.MissingMethodException 可能是缺少 initialization 的原因,并且可能与 this issue 相关。

    P.S.S:尝试删除 bin 和 obj 目录并重建 + 确保您只安装了一个版本的 NuGet 包。

    【讨论】:

    • 尝试您的建议,但再次得到相同的异常:MissingmethodException。我使用完整的异常详细信息编辑问题
    • 你确定你尝试了我建议的确切方法吗 => await Navigation.PushPopupAsync(new MyPopUpPage());而不是 await PopupNavigation.Instance.PushAsync(page);
    • 我尝试这样 await Application.Current.MainPage.Navigation.PushPopupAsync(new Pages.MyPopUpPage());
    • 不幸的是那不一样。取决于项目的导航堆栈。
    • 也试过 await Navigation.PushPopupAsync(new Pages.MyPopUpPage());得到的导航在当前上下文中不存在错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    相关资源
    最近更新 更多