This article is the third section of isolated storage. Let's have a cup of coffee to relax. Today's content is also very simple. Let's talk about something-user settings.
Of course, the translation may be suitable for application settings, but it doesn't matter as long as you understand that it is used to save the settings of our application.
It belongs to the dictionary set. The data stored in each item is stored in the form of a key-value pair. The key value is of the string type and cannot be null. Note that, otherwise, an exception is thrown. Of course, it is estimated that no one is so boring to save the null value.
It is easy to use. An isolatedstoragesettings instance is returned if the applicationsettings of isolatedstoragesettings is static.
1. You can call the add method to add data to a set. Its definition is as follows:
Public void add (string key, object value)
I believe everyone knows how to use it.
2. Use the contains (string key) method to check whether a key exists. This is required when reading the last saved data.
3. You don't need to introduce the clear method. When you look at the name, you will find it terrible. If you are not careful, all the settings you write will be cleared. Of course, before you call the Save method, the data has not been written to the isolated storage zone.
4. Remove (string key) method. You can call this method when you think that a setting is not needed, or you think it has a bad character and needs to be deleted, even if you are a QQ group owner and want to kill a member with a lower character value, you must first know the TA's QQ number or nickname.
5. Save. You know.
It's not too late. You will understand it right away when you do exercises.
This example is simple. Enter a value in two text boxes and save it when you exit the page. When you navigate to the page, the data is automatically loaded and saved to the isolated storage.
[HTML]View plaincopyprint?
- <Phone: phoneapplicationpage
- X: class = "phoneapp1.mainpage"
- Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
- Xmlns: Phone = "CLR-namespace: Microsoft. Phone. controls; Assembly = Microsoft. Phone"
- Xmlns: shell = "CLR-namespace: Microsoft. Phone. Shell; Assembly = Microsoft. Phone"
- Xmlns: D = "http://schemas.microsoft.com/expression/blend/2008"
- Xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
- MC: ignorable = "D" D: designwidth = "480" D: designheight = "768"
- Fontfamily = "{staticresource phonefontfamilynormal }"
- Fontsize = "{staticresource phonefontsizenormal }"
- Foreground = "{staticresource phoneforegroundbrush }"
- Supportedorientations = "portrait" orientation = "portrait"
- Shell: systemtray. isvisible = "true">
- <! -- Layoutroot is the root mesh that contains all page content -->
- <Grid X: Name = "layoutroot" background = "Transparent">
- <Grid. rowdefinitions>
- <Rowdefinition Height = "Auto"/>
- <Rowdefinition Height = "*"/>
- </Grid. rowdefinitions>
- <! -- Titlepanel contains the application name and page title -->
- <Stackpanel X: Name = "titlepanel" grid. Row = "0" margin = ",">
- <Textblock X: Name = "applicationtitle" text = "My applications" style = "{staticresource phonetextnormalstyle}"/>
- <Textblock X: Name = "pagetitle" text = "application settings" margin = "9,-7,0, 0" style = "{staticresource phonetexttitle1style}"/>
- </Stackpanel>
- <! -- Contentpanel-place other content here -->
- <Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0">
- <Textblock Height = "30" horizontalalignment = "Left" margin = "33,50, 0,0" name = "textblock1" text = "name:" verticalignment = "TOP"/>
- <Textblock Height = "30" horizontalalignment = "Left" margin = "33,116," name = "textblock2" text = "Occupation:" verticalalignment = "TOP"/>
- <Textbox Height = "72" horizontalalignment = "Left" margin = "116,25, 0,0" name = "txtname" text = "" verticalalignment = "TOP" width = "292"/>
- <Textbox Height = "72" horizontalalignment = "Left" margin = "116,104, 292" name = "txtpos" text = "" verticalalignment = "TOP" width = ""/>
- </GRID>
- </GRID>
- </Phone: phoneapplicationpage>
[CSHARP]View plaincopyprint?
- Using system;
- Using system. Collections. Generic;
- Using system. LINQ;
- Using system. net;
- Using system. windows;
- Using system. Windows. controls;
- Using system. Windows. documents;
- Using system. Windows. input;
- Using system. Windows. Media;
- Using system. Windows. Media. animation;
- Using system. Windows. shapes;
- Using Microsoft. Phone. controls;
- Using system. Io. isolatedstorage;
- Namespace phoneapp1
- {
- Public partial class mainpage: phoneapplicationpage
- {
- // Declare an isolatedstoragesettings variable.
- Isolatedstoragesetaskmysetting = isolatedstoragesettings. applicationsettings;
- // Constructor
- Public mainpage ()
- {
- Initializecomponent ();
- }
- Protected override void onnavigatedfrom (system. Windows. Navigation. navigationeventargs E)
- {
- Base. onnavigatedfrom (E );
- Mysetting ["name"] = this.txt name. text;
- Mysetting ["POS"] = txtpos. text;
- // Save
- Mysetting. Save ();
- }
- Protected override void onnavigatedto (system. Windows. Navigation. navigationeventargs E)
- {
- Base. onnavigatedto (E );
- // When you navigate to the page, read the data.
- If (mysetting. Contains ("name "))
- {
- Txtname. Text = mysetting ["name"] as string;
- }
- If (mysetting. Contains ("POS "))
- {
- Txtpos. Text = mysetting ["POS"] as string;
- }
- }
- }
- }
Okay. Look, isn't it easy?
Isolated storage is blowing here. Starting from the next article, we don't play with abstraction. Let's start with "What you see is what you see" and work together as a shanzhai painter. From the next section, we will discuss graphics, painting brushes, and drawing-related content.