In this section, we will look at how to go about creating a new Razor template solution using Xamarin Studio. We will begin by developing the basic structure for our application, as well as adding all the necessary database models and user interface files.
Before we can proceed, we need to create the BookLibrary
project. It is very simple to create this using Xamarin Studio. Simply follow the given steps:
BookLibrary
as the name for your app in the App Name field as well as specifying a name for the Organization Identifier field.
Once your project has been created, you will be presented with the Xamarin Studio development environment, along with several project files that the template created for your Razor template Solution, as shown in the following screenshot:
As you can see from the preceding screenshot, the BookLibrary
solution has been divided into three separate folders. The following table provides a brief description of what each area is used for:
Folder type |
Description |
|
This section is responsible for representing the model that our views will use, and contains a structure of fields that will be displayed and/or written to by our Razor templates. |
|
This section contains a place for you to add the images and CSS, or JavaScript files that your application will use. |
|
This section is responsible for containing all of the HTML5 Razor templates that your application will be referencing, and they need to contain and be prefixed with the |
One thing you will notice is that our solution contains a file called style.css
. This is because our application is essentially a hybrid mobile solution, and contains the files you might expect from a web solution, as can be seen in the following code snippet:
/* This is a minimal style sheet intended to demonstrate how to include static content in your hybrid app. Other static content, such as javascript files and images, can be included in this same folder(Resources on iOS or Assets on Android), with the same Build Action(BundleResource on iOS or AndroidAsset on Android), to be accessible from a path starting at the root of your hybrid application. */ #page { margin-top:10px; }
As you can see, this file doesn't contain much information, but as we work our way through this chapter, we will be adding to this file, and building the Razor template user-interface files.
Now that we have created our BookLibrary
solution, the next step is to add the SQLite.Net
NuGet package to our solution, since this doesn't get added automatically for us. The SQLite.Net
package will essentially provide us with the ability to have our application write to an SQLite database, to store our book details.
Let's look at how to add the SQLite.NETNuGet
package within our BookLibrary
solution, by performing the following steps:
Packages
folder that is contained within the BookLibrary
solution, and choose the Add Packages... menu option, as shown in the following screenshot.
SQLite.Net
within the search dialog, and then click on the sqlite-net option within the list, as shown in the following screenshot:
When you click on the Add Package button, you will notice that the package manager will create two new files for us within our solution. These are called SQLite.cs
and SQLiteAsync.cs
, and are basically wrapper convenience classes that allow .NET and Mono applications to store data within a SQLite 3 database.
Now that you have added the NuGet
package for the sqlite-net library, we can begin to utilize this library within the BookLibrary
solution that we will be covering in the next section.
3.138.120.136