HTML and CSS Reference
In-Depth Information
function _saveToSettings() {
localSettings.values["defaultPriority"] = that.defaultPriority;
};
return that;
});
TodoList.settings = new TodoListSettings();
Important
The exact position of this code is not particularly important, so long as it is
preceded by the definition of the
TodoList.Priority
object. It is suggested that you add this
code at top of the file right after the definition of the
TodoList
object and make it follow
only the definition of the
TodoList.Priority
object.
The
TodoListSettings
object is an object with one property—the
defaultPriority
property. This is
because in the current example you are going to have only one customizable option—the default
priority level of any newly created task. So far, you had it default to Normal; now you want to make
this value configurable on a per user basis.
However, the
TodoListSettings
object is not limited to defining the
defaultPriority
property; it also
features a couple of load/save methods. The idea is that the
TodoListSettings
object makes itself
responsible for loading and saving its content to a persistent store without requiring more than a
plain call to the
load
or
save
method. The details of how settings are persisted or retrieved are not
known outside the boundaries of the object.
In addition, an instance of the
TodoListSettings
object is created during the initialization of the
application and is made available through the
TodoList.settings
object. The bottom line is that in this
way, the application loads its settings from a persistent store at startup and these settings are globally
available for the entire lifecycle.
persisting application settings
Windows 8 provides applications with a system dictionary where data can be saved in pairs—a
unique ID and a corresponding value. Values can only be primitive types, such as strings and integers.
The system object that provides access to this data store is
Windows.Storage.ApplicationData.current.
localSettings
. The object exposes a
values
property that is the actual dictionary where data is stored.
For example, the default priority level set for the application is stored in an entry whose ID
matches the property name.
var priority = localSettings.values["defaultPriority"];
Search WWH ::
Custom Search