C # Learning (ix) Windows Store APP & WP Development Little Kee (i)

Source: Internet
Author: User

As the course has been told, the study record discusses some of the problems and gains I have encountered in Windows Store APP & WP Development.

One, the use of the database (Sqlite)

  
Although the data is very difficult to find, but the use of SQLite in these two platforms is very simple.

The first is the environment configuration phase:
1. Tools, expand and Update online, and then on the right to search SQLite, after downloading the installation of two tick expansion pack, Note to Restart the VS has been effective.

2. Project, manage NuGet packages online, search SQLite, install tick content, if the project more than two files is installed successfully.

  Note: If you have a problem with the CPU, you can finally change the target platform's anycpu to X64 or X86 according to your environment, right-click Project, Properties, and so on. at this point, the preparation is complete.

  

Let's talk about the use of SQLite:

1. Create a class to store the data. As shown in the following:

  

1  Publicdata Data//must be public2 {3 [Sqlite.autoincrement, sqlite.primarykey]//this sentence must be added, the primary key is used4          Public intId {Set;Get;} The primary key, SQLite used to identify the data, can not save the data we use, just to identify. If the data is stored, it must be guaranteed not to repeat5          Public stringName {Set;Get; } The following properties are used in the experiment6          Public stringContent {Set;Get; } All members must be public7}

2. Link the database and build the table, as shown in the following code

1 Privatesqliteconnection database;//Statement2 3  Private voidInit ()4  {5      stringDbPath = System.IO.Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path,"note.db"); Link is named note.db database file under current path, new if not present6Database =Newsqlite.sqliteconnection (DbPath);7Database. Createtable<data>();/////Insert the class name of the stored data that is written in the angle brackets8}

3. Change of data and additions

The first is the insertion of data, very simple, can be directly applied:

1  Public void Insert (data data) 2 {3   init ();//Initialize 45   database. Insert (data); Insert Operation 6   database. Savetransactionpoint ();  save breakpoint, must be added, otherwise it may be wrong!  7   database. Close (); Break link 8 }

The deletion of data is the same as inserting:

1  Public void Delete (data data) 2 {3    init (); 4     database. Delete (data); 5     database. Savetransactionpoint (); 6     database. Close (); 7  }

Data lookup, can be directly modeled after the situation write:

1  Public Sqlite.tablequery<data> Select (string  content)2{3     Init (); 4     return database. Table<data> (). Where (x = x.content== content);//Returns the data collection of Conte for incoming string 5  }

The actions for the results of the lookup are as follows:

1 New Database (); 2 var a = db. Select (); 3 4 foreach (var in a) 5 {6  //Perform each operation 7  }

The comprehensive use of the above content can be achieved on the database of diversified operations!

Two: Custom controls


I believe that every student has been troubled by the lack of their own heart to want the control, vs itself provides not to meet our desire. At this time, you can do your own, clothed, write your own exclusive control!

There are two ways to customize a control, one in XAML and one for pure C # code. To put it bluntly, a custom control is a combination of the original control into what it wants. For convenience and visualization, a custom control for XAML writing is given below.

1. First create a XAML file, right-click Project, add New item->xaml-> user control.

  

2. Combine various existing controls, here is a simple example of a delete confirmation interface:

  

1 <UserControl2     x:class= "note_wp." MyUserControl1 "3 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"4 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"5 xmlns:local= "USING:NOTE_WP"6 xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"7 XMLNS:MC= "http://schemas.openxmlformats.org/markup-compatibility/2006"8 mc:ignorable= "D"9 D:designheight= "+"Ten D:designwidth= "The "> One      A     <GridBackground= "LightBlue"> -         <TextBlockHorizontalAlignment= "Left"textwrapping= "Wrap"Text= "Confirm deletion?" "VerticalAlignment= "Top"Margin= "119,78,0,0"Height= " the"Width= "186"Foreground= "#FFEA1616"FontSize= "The "FontFamily= "Cambria"/> -         <ButtonContent= "Cancel"HorizontalAlignment= "Left"VerticalAlignment= "Top"Margin= "253,168,0,0"Background= "#FF834848"/> the         <ButtonContent= "OK"HorizontalAlignment= "Left"VerticalAlignment= "Top"Margin= "37,168,0,0"Background= "#FF8F4949"/> -     </Grid> - </UserControl>

As follows:

  

This control can then be used for other pages.

This study record ends, learning Little (ii) published next week ~ ~ ~

Hope that the teacher Daniel is not hesitate to enlighten you!

C # Learning (ix) Windows Store APP & WP Development Little Kee (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.