首页 > 解决方案 > Prism 库中的 Application 类是否持久存储数据?

问题描述

我目前正在使用 Prism 库来构建 Xamarin.Forms 应用程序。Prism 为开发人员提供了一个公开属性的接口“IApplicationStore”。我在我的应用程序中实现了接口。我想知道接口中公开的属性字典是否将数据持久存储到用户的设备,或者这些数据仅在应用程序打开或在后台可用时可用?Prism Library Github 页面上的文档并没有真正指定这一点。

标签: xamarin.forms

解决方案


这是 Github 上 Prism repo 上 ApplicationStore 的源代码:

using System.Collections.Generic;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Prism.AppModel
{
    public class ApplicationStore : IApplicationStore
    {
        public IDictionary<string, object> Properties
        {
            get { return Application.Current.Properties; }
        }

        public Task SavePropertiesAsync() =>
            Application.Current.SavePropertiesAsync();
    }
}

所以它只是 Xamarin.Forms 应用程序属性的包装器。如果要保留属性,只需调用 SavePropertiesAsync() 就可以了:

https://docs.microsoft.com/en-US/dotnet/api/xamarin.forms.application.savepropertiesasync?view=xamarin-forms


推荐阅读