Xamarin.Forms provides two solution templates for building cross-platform applications: PCL or Shared Project. This Todo sample application is provided using both templates. The Xamarin.Forms application code is fundamentally the same, except where the database connection is created (because it requires a file-system reference to the SQLite data file).
NOTE: Windows Phone requires you to download Precompiled Binaries for Windows Phone 8 VSIX and install in Visual Studio; this enables the SQLite for Windows Phone extension that you can then add to your app.
Right-click References and select Add Reference. Go to Windows Phone > Extensions and check the option SQLite for Windows Phone to add the extension to the project.
This solution uses the SQLite.NET PCL NuGet to provide a cross-platform implementation of the SQLite database API. The shared PCL project references the NuGet to implement the TaskDatabase
class. Platform-specific instances of the SQLiteConnection
are created and injected on each platform (in AppDelegate
, MainActivity
, and MainPage
).
This version uses the raw C# source of SQLite.NET in the Shared Project, which is accessed by the TaskDatabase
class. There is a compiler-directive (#if __IOS__
) in the TaskDatabase
class that is used to determine the correct filename for each platform.
Craig Dunn, Bryan Costanich