App settings storage refers to a dictionary collection of key/value pairs saved in the application store, which automatically takes care of serializing the object and saves it in the application. Provides a method of fast data access in key/value pairs, mainly for storing some application information.
1. Introduction to Application Settings
Application setting is a kind of encapsulated data storage in WINDOWS10, it has its own characteristics, and has certain restrictions on the stored data, before using the application settings need to be very clear that these characteristics and restrictions can be used well.
1) The hierarchy of the owning container
Refers to the settings information in a container, and the container can also nest nested containers, layers of nesting. Within the app data store where settings are applied, each app has a root container for the settings, and the relevant APIs allow you to add settings data and new containers to the root container, creating new containers that make it easy to organize various settings data, which is equivalent to a grouped function. A container is nested up to 32 layers deep.
2) There are both local and roaming settings types
Windows 10 supports both local and roaming types, where the data is only present in the current client application, while roaming means that the data is synced to the client in the same account as the other device. The local app settings are under the root container ApplicationData.Current.LocalSettings, while the roaming app settings are under the root container ApplicationData.Current.RoamingSettings, except that the root directory of the store is different, and the other API Done exactly the same.
3) Application settings support most Windows runtime data types
The data stored by the app settings does not support all types, such as collection types, and custom objects are not supported. The app settings support most Windows runtime data types, as follows:
Numeric types: UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, single, Double
Boolean Type: Boolean
Character type: Char16, String
Event Type: Datatime, TimeSpan
struct type: GUID, point, Size, Rect
Combination type: Applicationdatacompositevalue
There are two workarounds for types that are not supported by the app settings, one is to use an application file for storage, and the other is to serialize the data to a supported data type, such as JSON.
2. Apply Settings action
The application setting operation supports adding, deleting, changing and checking these basic operations. The first thing to get is the container object Applicationdatacontainer the app settings. The ApplicationData class represents the data class of an application, because an application has only one ApplicationData object, so the class uses Singleton mode to create the object, and the singleton object can be obtained through the Applicationdata.current property.
1) Add and modify app settings
Before you can apply settings related to the app, you need to get the app's settings, and the following code gets the local app settings container:
Applicationdatacontainer localsettings = Windows.Storage.ApplicationData.Current.LocalSettings;
After you get the container, add the data to the app settings and modify it if the app settings already exist. Use the Applicationdatacontainer.values property to access the settings in the LocalSettings container obtained in the previous step, and then manipulate the app settings by using key/value pairs. The following statement creates a setting named Testsetting:
localsettings.values["testsetting" "Hello windoes";
In the code shown above, if there is no "testsetting" key in the container to add a new one, if there is already an option to modify the original.
2) Read application settings
Also use the Applicationdatacontainer.values property to get the value of the app settings. The following code accesses the testsetting settings in the LocalSettings container.
String value = localsetting.value["testsetting"]. ToString ();
3) Delete app settings
Implemented by the Applicationdatacontainersettings.remove method.
LocalSetting.Value.Remove ("testsetting");
3. application file Storage
Application settings are limited by the amount of data and data types, so you also need to apply file storage to store data as files. In the app data store for each app, the app has a system-defined root directory: one for local files, one for roaming files, and one for temporary files. Apps can add new files and new directories to the root directory. The hierarchy limit for file storage and app settings is the same, nesting up to 32 layers deep, and the width of the tree is unlimited. The following describes the differences between the three types of application files, followed by the stored operations.
1) Local Application files
Local applications are stored only on the client's storage data, the stored data does not have a total size limit, and the storage area is the program's sandbox, only the application can access, other programs cannot access, so as to guarantee the security of the program. Since the local application file belongs to the application's own storage file, the data is also deleted when the application is uninstalled. The root directory of the local application file can be accessed through the Localfolder property of the ApplicationData object, that is, the ApplicationData.Current.LocalFolder type is the Stroagefolder object.
2) Roaming application files
Roaming app files are data shared by devices that are logged on to the same account, and this is the same example in roaming settings. Roaming data can easily sync app data across multiple devices
---restore content ends---
App settings storage refers to a dictionary collection of key/value pairs saved in the application store, which automatically takes care of serializing the object and saves it in the application. Provides a method of fast data access in key/value pairs, mainly for storing some application information.
1. Introduction to Application Settings
Application setting is a kind of encapsulated data storage in WINDOWS10, it has its own characteristics, and has certain restrictions on the stored data, before using the application settings need to be very clear that these characteristics and restrictions can be used well.
1) The hierarchy of the owning container
Refers to the settings information in a container, and the container can also nest nested containers, layers of nesting. Within the app data store where settings are applied, each app has a root container for the settings, and the relevant APIs allow you to add settings data and new containers to the root container, creating new containers that make it easy to organize various settings data, which is equivalent to a grouped function. A container is nested up to 32 layers deep.
2) There are both local and roaming settings types
Windows 10 supports both local and roaming types, where the data is only present in the current client application, while roaming means that the data is synced to the client in the same account as the other device. The local app settings are under the root container ApplicationData.Current.LocalSettings, while the roaming app settings are under the root container ApplicationData.Current.RoamingSettings, except that the root directory of the store is different, and the other API Done exactly the same.
3) Application settings support most Windows runtime data types
The data stored by the app settings does not support all types, such as collection types, and custom objects are not supported. The app settings support most Windows runtime data types, as follows:
Numeric types: UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, single, Double
Boolean Type: Boolean
Character type: Char16, String
Event Type: Datatime, TimeSpan
struct type: GUID, point, Size, Rect
Combination type: Applicationdatacompositevalue
There are two workarounds for types that are not supported by the app settings, one is to use an application file for storage, and the other is to serialize the data to a supported data type, such as JSON.
2. Apply Settings action
The application setting operation supports adding, deleting, changing and checking these basic operations. The first thing to get is the container object Applicationdatacontainer the app settings. The ApplicationData class represents the data class of an application, because an application has only one ApplicationData object, so the class uses Singleton mode to create the object, and the singleton object can be obtained through the Applicationdata.current property.
1) Add and modify app settings
Before you can apply settings related to the app, you need to get the app's settings, and the following code gets the local app settings container:
Applicationdatacontainer localsettings = Windows.Storage.ApplicationData.Current.LocalSettings;
After you get the container, add the data to the app settings and modify it if the app settings already exist. Use the Applicationdatacontainer.values property to access the settings in the LocalSettings container obtained in the previous step, and then manipulate the app settings by using key/value pairs. The following statement creates a setting named Testsetting:
localsettings.values["testsetting" "Hello windoes";
In the code shown above, if there is no "testsetting" key in the container to add a new one, if there is already an option to modify the original.
2) Read application settings
Also use the Applicationdatacontainer.values property to get the value of the app settings. The following code accesses the testsetting settings in the LocalSettings container.
String value = localsetting.value["testsetting"]. ToString ();
3) Delete app settings
Implemented by the Applicationdatacontainersettings.remove method.
LocalSetting.Value.Remove ("testsetting");
Reading notes 4:UWP application settings storage