Windows Phone development (29): isolated storage C-: http://blog.csdn.net/tcjiaan/article/details/7447469

Source: Internet
Author: User

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?

  1. <Phone: phoneapplicationpage
  2. X: class = "phoneapp1.mainpage"
  3. Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
  5. Xmlns: Phone = "CLR-namespace: Microsoft. Phone. controls; Assembly = Microsoft. Phone"
  6. Xmlns: shell = "CLR-namespace: Microsoft. Phone. Shell; Assembly = Microsoft. Phone"
  7. Xmlns: D = "http://schemas.microsoft.com/expression/blend/2008"
  8. Xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
  9. MC: ignorable = "D" D: designwidth = "480" D: designheight = "768"
  10. Fontfamily = "{staticresource phonefontfamilynormal }"
  11. Fontsize = "{staticresource phonefontsizenormal }"
  12. Foreground = "{staticresource phoneforegroundbrush }"
  13. Supportedorientations = "portrait" orientation = "portrait"
  14. Shell: systemtray. isvisible = "true">
  15. <! -- Layoutroot is the root mesh that contains all page content -->
  16. <Grid X: Name = "layoutroot" background = "Transparent">
  17. <Grid. rowdefinitions>
  18. <Rowdefinition Height = "Auto"/>
  19. <Rowdefinition Height = "*"/>
  20. </Grid. rowdefinitions>
  21. <! -- Titlepanel contains the application name and page title -->
  22. <Stackpanel X: Name = "titlepanel" grid. Row = "0" margin = ",">
  23. <Textblock X: Name = "applicationtitle" text = "My applications" style = "{staticresource phonetextnormalstyle}"/>
  24. <Textblock X: Name = "pagetitle" text = "application settings" margin = "9,-7,0, 0" style = "{staticresource phonetexttitle1style}"/>
  25. </Stackpanel>
  26. <! -- Contentpanel-place other content here -->
  27. <Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0">
  28. <Textblock Height = "30" horizontalalignment = "Left" margin = "33,50, 0,0" name = "textblock1" text = "name:" verticalignment = "TOP"/>
  29. <Textblock Height = "30" horizontalalignment = "Left" margin = "33,116," name = "textblock2" text = "Occupation:" verticalalignment = "TOP"/>
  30. <Textbox Height = "72" horizontalalignment = "Left" margin = "116,25, 0,0" name = "txtname" text = "" verticalalignment = "TOP" width = "292"/>
  31. <Textbox Height = "72" horizontalalignment = "Left" margin = "116,104, 292" name = "txtpos" text = "" verticalalignment = "TOP" width = ""/>
  32. </GRID>
  33. </GRID>
  34. </Phone: phoneapplicationpage>

 

[CSHARP]View plaincopyprint?

  1. Using system;
  2. Using system. Collections. Generic;
  3. Using system. LINQ;
  4. Using system. net;
  5. Using system. windows;
  6. Using system. Windows. controls;
  7. Using system. Windows. documents;
  8. Using system. Windows. input;
  9. Using system. Windows. Media;
  10. Using system. Windows. Media. animation;
  11. Using system. Windows. shapes;
  12. Using Microsoft. Phone. controls;
  13. Using system. Io. isolatedstorage;
  14. Namespace phoneapp1
  15. {
  16. Public partial class mainpage: phoneapplicationpage
  17. {
  18. // Declare an isolatedstoragesettings variable.
  19. Isolatedstoragesetaskmysetting = isolatedstoragesettings. applicationsettings;
  20. // Constructor
  21. Public mainpage ()
  22. {
  23. Initializecomponent ();
  24. }
  25. Protected override void onnavigatedfrom (system. Windows. Navigation. navigationeventargs E)
  26. {
  27. Base. onnavigatedfrom (E );
  28. Mysetting ["name"] = this.txt name. text;
  29. Mysetting ["POS"] = txtpos. text;
  30. // Save
  31. Mysetting. Save ();
  32. }
  33. Protected override void onnavigatedto (system. Windows. Navigation. navigationeventargs E)
  34. {
  35. Base. onnavigatedto (E );
  36. // When you navigate to the page, read the data.
  37. If (mysetting. Contains ("name "))
  38. {
  39. Txtname. Text = mysetting ["name"] as string;
  40. }
  41. If (mysetting. Contains ("POS "))
  42. {
  43. Txtpos. Text = mysetting ["POS"] as string;
  44. }
  45. }
  46. }
  47. }

 

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.

Related Article

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.