ApplicationDataContainerSettings
ApplicationDataContainerSettings
ApplicationDataContainerSettings
ApplicationDataContainerSettings
Class
Definition
Provides access to the settings in a settings container. The ApplicationDataContainer.Values property returns an object that can be cast to this type.
public : sealed class ApplicationDataContainerSettings : IIterable, IMap, IObservableMap, IPropertySetpublic sealed class ApplicationDataContainerSettings : IEnumerable, IDictionary, IObservableMap, IPropertySetPublic NotInheritable Class ApplicationDataContainerSettings Implements IEnumerable, IDictionary, IObservableMap, IPropertySet// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
To get an app's local settings, do the following things. These steps are demonstrated in the LocalSettings example.
- Get the value of the static ApplicationData.Current property. This property returns a data store of type ApplicationData.
- Get the value of the data store's LocalSettings property. This property returns a data container of type ApplicationDataContainer.
- Read the Values property of the data container. This property returns a group of settings of type IPropertySet, which can be cast to the ApplicationDataContainerSettings type.
Collection member lists
Note that for JavaScript, ApplicationDataContainerSettings supports using an index to access items.
Properties
Item[TKey] Item[TKey] Item[TKey] Item[TKey]
Gets or sets the element with the specified key.
This member is not implemented in C++TValue this[TKey key] { get; set; }Property Item(key As TKey) As TValueTValue this[TKey key] { get; set; }
- key
- TKey TKey TKey TKey
The key of the element to get or set.
- Value
- TValue TValue TValue TValue
The element with the specified key.
key is null.
The property is retrieved and key is not found.
The property is set and the System.Collections.Generic.IDictionary`2 is read-only.
Keys Keys Keys Keys
Gets an System.Collections.Generic.ICollection`1 containing the keys of the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++ICollection<TKey> Keys { get; }ReadOnly Property Keys As ICollection(Of TKey)ICollection<TKey> Keys { get; }
- Value
An System.Collections.Generic.ICollection`1 containing the keys of the object that implements System.Collections.Generic.IDictionary`2.
Size Size Size Size
Gets the number of related application settings.
public : unsigned int Size { get; }This member is not implemented in C#This member is not implemented in VB.Net// You can use this property in JavaScript.
- Value
- unsigned int uint uint uint
The number of related settings.
Values Values Values Values
Gets an System.Collections.Generic.ICollection`1 containing the values in the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++ICollection<TValue> Values { get; }ReadOnly Property Values As ICollection(Of TValue)ICollection<TValue> Values { get; }
- Value
An System.Collections.Generic.ICollection`1 containing the values in the object that implements System.Collections.Generic.IDictionary`2.
Methods
Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue)
Adds an element with the provided key and value to the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++void Add(TKey key, TValue value)Sub Add(key As TKey, value As TValue)void Add(TKey key, TValue value)
- key
- TKey TKey TKey TKey
The object to use as the key of the element to add.
- value
- TValue TValue TValue TValue
The object to use as the value of the element to add.
key is null.
An element with the same key already exists in the System.Collections.Generic.IDictionary`2.
The System.Collections.Generic.IDictionary`2 is read-only.
Clear() Clear() Clear() Clear()
Removes all related application settings.
public : void Clear()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey)
Determines whether the System.Collections.Generic.IDictionary`2 contains an element with the specified key.
This member is not implemented in C++bool ContainsKey(TKey key)Function ContainsKey(key As TKey) As Booleanbool ContainsKey(TKey key)
- key
- TKey TKey TKey TKey
The key to locate in the System.Collections.Generic.IDictionary`2.
true if the System.Collections.Generic.IDictionary`2 contains an element with the key; otherwise, false.
key is null.
First() First() First() First()
Retrieves an iterator to enumerate the settings in the settings container.
public : IIterator<IKeyValuePair<PlatForm::String, PlatForm::Object>> First()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
The iterator.
Remarks
This iterator remains valid even if the container's contents are mutated. If the container is mutated, you must get a new iterator to see the updated contents of the settings container.
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()
Returns an enumerator that iterates through the collection.
This member is not implemented in C++IEnumerator<T> GetEnumerator()Function GetEnumerator As IEnumerator(Of T)IEnumerator<T> GetEnumerator()
An enumerator that can be used to iterate through the collection.
GetView() GetView() GetView() GetView()
Returns a read-only snapshot of the contents of the settings container.
public : IMapView<PlatForm::String, PlatForm::Object> GetView()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
The view of the settings container.
Remarks
If the container is mutated, you must get a new view to see the updated contents of the settings container.
HasKey(String) HasKey(String) HasKey(String) HasKey(String)
Determines whether there is an application setting with the specified key.
public : PlatForm::Boolean HasKey(PlatForm::String key)This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
- key
- PlatForm::String String String String
The key.
True if the key is found; otherwise false.
Examples
Call the ApplicationDataContainer.CreateContainer | createContainer method to create a settings container. This example creates a settings container named exampleContainer and adds a setting named exampleSetting. The Always | always value from the ApplicationDataCreateDisposition enumeration indicates that the container should be created if it does not already exist.
Use the ApplicationDataContainer.Values | values property to access the exampleSetting setting in the exampleContainer container.
Call the ApplicationDataContainer.DeleteContainer | deleteContainer method to delete the exampleContainer settings container when you have finished with it.
var applicationData = Windows.Storage.ApplicationData.current;
var localSettings = applicationData.localSettings;
// Create a setting in a container
var container = localSettings.createContainer("exampleContainer",
Windows.Storage.ApplicationDataCreateDisposition.Always);
if (localSettings.containers.hasKey("exampleContainer"))
{
localSettings.containers.lookup("exampleContainer").values["exampleSetting"] = "Hello Windows";
}
// Read data from a setting in a container
var hasContainer = localSettings.containers.hasKey("exampleContainer");
if (hasContainer)
{
// Access data in:
// localSettings.containers.lookup("exampleContainer").values.hasKey("exampleSetting");
}
// Delete a container
localSettings.deleteContainer("exampleContainer");
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a setting in a container
Windows.Storage.ApplicationDataContainer container =
localSettings.CreateContainer("exampleContainer", Windows.Storage.ApplicationDataCreateDisposition.Always);
if (localSettings.Containers.ContainsKey("exampleContainer"))
{
localSettings.Containers["exampleContainer"].Values["exampleSetting"] = "Hello Windows";
}
// Read data from a setting in a container
bool hasContainer = localSettings.Containers.ContainsKey("exampleContainer");
bool hasSetting = false;
if (hasContainer)
{
hasSetting = localSettings.Containers["exampleContainer"].Values.ContainsKey("exampleSetting");
}
// Delete a container
localSettings.DeleteContainer("exampleContainer");
Dim localSettings As Windows.Storage.ApplicationDataContainer = Windows.Storage.ApplicationData.Current.LocalSettings
' Create a setting in a container
Dim container As Windows.Storage.ApplicationDataContainer =
localSettings.CreateContainer("exampleContainer", Windows.Storage.ApplicationDataCreateDisposition.Always)
If localSettings.Containers.ContainsKey("exampleContainer") Then
localSettings.Containers("exampleContainer").Values("exampleSetting") = "Hello Windows"
End If
' Read data from a setting in a container
Dim hasContainer As Boolean = localSettings.Containers.ContainsKey("exampleContainer")
Dim hasSetting As Boolean = False
If hasContainer Then
hasSetting = localSettings.Containers("exampleContainer").Values.ContainsKey("exampleSetting")
End If
' Delete a container
localSettings.DeleteContainer("exampleContainer")
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
// Create a setting in a container
ApplicationDataContainer^ container =
localSettings->CreateContainer("exampleContainer", ApplicationDataCreateDisposition::Always);
if (localSettings->Containers->HasKey("exampleContainer"))
{
auto values = localSettings->Containers->Lookup("exampleContainer")->Values;
values->Insert("exampleSetting", "Hello Windows");
}
// Read data from a setting in a container
bool hasContainer = localSettings->Containers->HasKey("exampleContainer");
bool hasSetting = false;
if (hasContainer)
{
auto values = localSettings->Containers->Lookup("exampleContainer")->Values;
hasSetting = values->HasKey("exampleSetting");
}
// Delete a container
localSettings->DeleteContainer("exampleContainer");
- See Also
Insert(String, Object) Insert(String, Object) Insert(String, Object) Insert(String, Object)
Inserts or replaces an application setting.
public : PlatForm::Boolean Insert(PlatForm::String key, PlatForm::Object value)This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
- key
- PlatForm::String String String String
The key of the setting to insert or replace.
- value
- PlatForm::Object Object Object Object
The setting value.
True if an item with the specified key is an existing item and was replaced; otherwise, false.
Lookup(String) Lookup(String) Lookup(String) Lookup(String)
Retrieves the specified application setting.
public : PlatForm::Object Lookup(PlatForm::String key)This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
- key
- PlatForm::String String String String
The key of the setting.
The value, if an item with the specified key exists. Use the HasKey method to determine whether the key exists.
Remarks
For a code example of Lookup, see the HasKey example.
- See Also
Remove(TKey) Remove(TKey) Remove(TKey) Remove(TKey)
Removes the element with the specified key from the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++bool Remove(TKey key)Function Remove(key As TKey) As Booleanbool Remove(TKey key)
- key
- TKey TKey TKey TKey
The key of the element to remove.
true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original System.Collections.Generic.IDictionary`2.
key is null.
The System.Collections.Generic.IDictionary`2 is read-only.
Remove(String) Remove(String) Remove(String) Remove(String)
Removes the specified application setting.
public : void Remove(PlatForm::String key)This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
- key
- PlatForm::String String String String
The key of the setting.
Remarks
For the C# and Microsoft Visual Basic version of the Remove(String) method, see Remove.
- See Also
TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
This member is not implemented in C++bool TryGetValue(TKey key, out TValue value)Function TryGetValue(key As TKey, ByRef value As TValue) As Booleanbool TryGetValue(TKey key, out TValue value)
- key
- TKey TKey TKey TKey
The key whose value to get.
- value
- TValue TValue TValue TValue
When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
true if the object that implements System.Collections.Generic.IDictionary`2 contains an element with the specified key; otherwise, false.
key is null.