Xamarin Forms Update ListView on WillEnterForeground

本文关键字:on WillEnterForeground ListView Update Forms Xamarin | 更新日期: 2023-09-27 18:33:05

Objective

更新 Xamarin.Forms 列表视图时 iOS 应用程序进入前台

方法

我看到的关闭示例可在单点触摸样本中找到

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 页面,并且不知道如何从应用程序委托类访问页面或页面的视图模型。 有什么想法吗?

Xamarin Forms Update ListView on WillEnterForeground

当您将

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

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