【问题标题】:Xamarin Forms Prism call the methodXamarin Forms Prism 调用方法
【发布时间】:2018-05-25 11:55:23
【问题描述】:

页面出现后如何调用异步方法? 我试图通过在 ContentPage 中覆盖 OnAppearing() 来做到这一点,这对我也不起作用。

【问题讨论】:

    标签: c# xamarin xamarin.forms xamarin.android prism


    【解决方案1】:

    OnAppearing 本质上是一个隐藏发送者和 EventArgs 的事件处理程序。如果您需要异步执行此操作,只需将其设为 async:

    protected override async void OnAppearing()
    {
        await FooAsync();
    }
    

    由于您为 Prism 添加了标签,因此我将添加,当遵循 MVVM 模式时,您应该只在以视图为中心的代码隐藏中执行代码。换句话说,此代码应仅限于更改视图的某些内容。 Prism 7 确实为您提供了 IPageLifecycleAware 接口,因此您可以在 ViewModel 中处理 OnAppearingOnDisappearing

    【讨论】:

      猜你喜欢
      • 2018-10-19
      • 1970-01-01
      • 2016-06-06
      • 1970-01-01
      • 2018-07-21
      • 2018-02-09
      • 2016-12-05
      • 2020-03-27
      • 1970-01-01
      相关资源
      最近更新 更多