【问题标题】:Xamarin Forms Using Statements Not Available使用不可用语句的 Xamarin 表单
【发布时间】:2016-10-18 18:00:17
【问题描述】:

我是 Xamarin Forms 和 Xamarin 的新手。我可能误解了架构的工作原理,或者我可能在网上遵循了不同的示例。我正在尝试尽可能多地使用Portable Class Library

我的 nuget 包是 Xamarin.FormsSQLite.Net-PCL。它们安装在所有设备上,Droid、ios、windows 和 PCL。绝对是最新验证的最高下载量。我正在遵循这些指南

https://github.com/xamarin/xamarin-forms-samples/tree/2f6715c5a9dc0f057279d2b2c268e872eaa483bc/Todo/PCL

https://developer.xamarin.com/guides/xamarin-forms/working-with/databases/

在 SQLite 接口的 SQLite_Droid 实现上,我无法访问 Xamarin.Forms using 语句或具有接口的语句,这是Native_PCL 项目中的所有代码。

ISQLite.cs

using SQLite.Net;

namespace Native_PCL.DataServices
{
    interface ISQLite
    {
        SQLiteConnection GetConnection();
    }
}

DataCalls.cs

using System.Linq;
using SQLite.Net;
using Xamarin.Forms;
using Native_PCL.Data;

namespace Native_PCL.DataServices
{
    public class DataCalls
    {
        static object locker = new object();

        SQLiteConnection db;

        public DataCalls()
        {
            db = DependencyService.Get<ISQLite>().GetConnection();

            db.CreateTable<UserPreferences>();
            db.CreateTable<Orders>();
        }

        public void SubmitData(Orders order, out string update)
        {
            lock (locker)
            {
                if (!db.Table<Orders>().Any(x => x.foodName == order.foodName))
                {
                    db.Insert(order);
                    update = order.foodName;
                }
                else { update = order.foodName + " was already in your Order"; }
            }
        }
    }
}

这是Native_PCL.Droid项目中的所有代码

SQLite_Droid.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content; // for some reason all of the System. and Android. are showing white. Usually unused statements are grayed out!
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

using Native_PCL;
using Native_PCL. ; /// only .Droid is registering
using Xamarin.Forms; //Intellisense does not pick this up


namespace Native_PCL.Droid.DataImplement
{
    public class SQLite_Droid : Native_PCL.DataServices.ISQLite /// All white, Doesn't register the ISQLite as an Interface.
    {
    }
}

我已经重新创建了整个项目。我一定是做错了什么。

【问题讨论】:

    标签: c# sqlite xamarin.android


    【解决方案1】:

    拔掉大部分头发后,我不得不想,这不可能是我。我编译了,有几个错误。我决定去Android解决方案中的MainActivity.cs。原来样板新鲜项目找不到App。以下是解决我的问题的步骤。

    1. 转到/Users/XXXXXX/AppData/Local/Xamarin我删除了除log和zips之外的所有文件夹,但我删除了zip文件夹中的压缩文件。

    2. 转到解决方案资源管理器,右键单击解决方案,然后Clean Solution

    3. 从 Android 项目中删除了对 Portable Class library 项目的引用。
    4. 编译基础Portable Class library 项目。
    5. 重新添加了对 Android 项目的引用。

    这个故事的教训是,如果您遇到的智能感知问题没有获取应该存在的参考,请按照步骤 2、3、4、5 进行操作。而且因为它是 Xamarin 并且涉及模拟器和交叉兼容性,所以请按照步骤 1。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 2013-12-01
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2021-04-29
      相关资源
      最近更新 更多