WillEnterForeground 上的 Xamarin 表单更新 ListView

Posted

技术标签:

【中文标题】WillEnterForeground 上的 Xamarin 表单更新 ListView【英文标题】:Xamarin Forms Update ListView on WillEnterForeground 【发布时间】:2015-02-02 19:03:58 【问题描述】:

目标

ios 应用程序进入前台时更新 Xamarin.Forms ListView

接近

我在单点触控示例中看到的关闭示例

https://github.com/xamarin/monotouch-samples/blob/master/SimpleBackgroundFetch/SimpleBackgroundFetch/AppDelegate.cs

public override void PerformFetch (UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
        
            UINavigationController navigationController = Window.RootViewController as UINavigationController;
            UIViewController topViewController = navigationController.TopViewController;
            if (topViewController is RootViewController) 
                (topViewController as RootViewController).InsertNewObjectForFetch (completionHandler);
                UIApplication.SharedApplication.ApplicationIconBadgeNumber++;
             else
                completionHandler (UIBackgroundFetchResult.Failed);
        

这是使用 PerformFetch 但 WillEnterForegroundMethod 将完成我想要做的事情。

问题

问题是我正在使用 Xamarin.Form 页面,但不知道如何从 App Delegate 类访问页面或页面的 ViewModel。有什么想法吗?

【问题讨论】:

【参考方案1】:

当您将 ViewModel 设置为 View 的 BindingContext 时,您可以将 ViewModel 注册到 IoC 容器,然后使用它来获取它。

如果您使用的是 MVVMLight,SimpleIoC 包含在该软件包中。

【讨论】:

以上是关于WillEnterForeground 上的 Xamarin 表单更新 ListView的主要内容,如果未能解决你的问题,请参考以下文章