【问题标题】:Adding UWP option to Xamarin cross-platform application将 UWP 选项添加到 Xamarin 跨平台应用程序
【发布时间】:2017-08-20 15:23:38
【问题描述】:

我为 Android 和 IOS 制作了一个简单的 Xamarin 跨平台 sqlite 应用程序。我也想添加通用 Windows Phone 版本。为此,我遵循this 步骤。我从 nuget 管理器安装了 SQLite.Net-PCL。但我仍然需要为 sqlite 连接写一些东西。在this 链接中,第 6 步有此代码,但它适用于 windows phone 8。您能帮帮我吗?

【问题讨论】:

    标签: sqlite xamarin uwp


    【解决方案1】:

    Xamarin.Forms 支持使用 SQLite 数据库引擎的数据库驱动应用程序,这使得在共享代码中加载和保存对象成为可能。

    Xamarin.Forms 应用程序可以使用 SQLite.NET PCL NuGet 包通过引用 NuGet 中附带的 SQLite 类将数据库操作合并到共享代码中。数据库操作可以在 Xamarin.Forms 解决方案的可移植类库 (PCL) 项目中定义,特定于平台的项目会返回存储数据库的路径。

    但是我仍然需要为 sqlite 连接写一些东西。在此链接中,第 6 步有此代码,但它适用于 windows phone 8。您能帮帮我吗?

    Windows 10 通用 Windows 平台 (UWP) 通过右键单击并选择 Manage NuGet Packages,将 SQLite-net PCL NuGet 添加到 UWP 项目。

    添加引用后,使用特定于平台的 Windows.Storage API 实现 IFileHelper 接口以确定数据文件路径。

    using Windows.Storage;
    ...
    
    [assembly: Dependency(typeof(FileHelper))]
    namespace Todo.UWP
    {
        public class FileHelper : IFileHelper
        {
            public string GetLocalFilePath(string filename)
            {
                return Path.Combine(ApplicationData.Current.LocalFolder.Path, filename);
            }
        }
    }
    

    详情请参考 Xamarin.Forms Local Databases。随附的sample application 是一个简单的待办事项列表应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多