Application​Data​Container​Settings Application​Data​Container​Settings Application​Data​Container​Settings 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
Attributes
Windows 10 requirements
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.

  1. Get the value of the static ApplicationData.Current property. This property returns a data store of type ApplicationData.
  2. Get the value of the data store's LocalSettings property. This property returns a data container of type ApplicationDataContainer.
  3. 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]

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 TValue
Parameters
key
TKey TKey TKey

The key of the element to get or set.

Value
TValue TValue TValue

The element with the specified key.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

System.Collections.Generic.KeyNotFoundException System.Collections.Generic.KeyNotFoundException System.Collections.Generic.KeyNotFoundException

The property is retrieved and key is not found.

System.NotSupportedException System.NotSupportedException System.NotSupportedException

The property is set and the System.Collections.Generic.IDictionary`2 is read-only.

See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

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)
Value
System.Collections.Generic.ICollection<TKey> System.Collections.Generic.ICollection<TKey> System.Collections.Generic.ICollection<TKey>

An System.Collections.Generic.ICollection`1 containing the keys of the object that implements System.Collections.Generic.IDictionary`2.

Attributes
See Also
System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>

Size Size Size

Gets the number of related application settings.

public unsigned short Size { get; }This member is not implemented in C#This member is not implemented in VB.Net
Value
uint uint uint

The number of related settings.

Attributes

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)
Value
System.Collections.Generic.ICollection<TValue> System.Collections.Generic.ICollection<TValue> System.Collections.Generic.ICollection<TValue>

An System.Collections.Generic.ICollection`1 containing the values in the object that implements System.Collections.Generic.IDictionary`2.

Attributes
See Also
System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>

Methods

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)
Parameters
key
TKey TKey TKey

The object to use as the key of the element to add.

value
TValue TValue TValue

The object to use as the value of the element to add.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

System.ArgumentException System.ArgumentException System.ArgumentException

An element with the same key already exists in the System.Collections.Generic.IDictionary`2.

System.NotSupportedException System.NotSupportedException System.NotSupportedException

The System.Collections.Generic.IDictionary`2 is read-only.

See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

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
Attributes

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 Boolean
Parameters
key
TKey TKey TKey

The key to locate in the System.Collections.Generic.IDictionary`2.

Returns
System.Boolean System.Boolean System.Boolean

true if the System.Collections.Generic.IDictionary`2 contains an element with the key; otherwise, false.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

First() First() First()

Retrieves an iterator to enumerate the settings in the settings container.

public IIterator<IKeyValuePair<string, object>> First()This member is not implemented in C#This member is not implemented in VB.Net
Returns

The iterator.

Attributes

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()

Returns an enumerator that iterates through the collection.

This member is not implemented in C++IEnumerator<T> GetEnumerator()Function GetEnumerator As IEnumerator(Of T)
Returns
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T>

An enumerator that can be used to iterate through the collection.

Attributes
See Also
System.Collections.Generic.IEnumerator<T>System.Collections.Generic.IEnumerator<T>System.Collections.Generic.IEnumerator<T>

GetView() GetView() GetView()

Returns a read-only snapshot of the contents of the settings container.

public IMapView<string, object> GetView()This member is not implemented in C#This member is not implemented in VB.Net
Returns

The view of the settings container.

Attributes

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)

Determines whether there is an application setting with the specified key.

public PlatForm::Boolean HasKey(String key)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key.

Returns
bool bool bool

True if the key is found; otherwise false.

Attributes

Remarks

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)

Inserts or replaces an application setting.

public PlatForm::Boolean Insert(String key, Object value)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key of the setting to insert or replace.

value
System.Object System.Object System.Object

The setting value.

Returns
bool bool bool

True if an item with the specified key is an existing item and was replaced; otherwise, false.

Attributes

Lookup(String) Lookup(String) Lookup(String)

Retrieves the specified application setting.

public PlatForm::Object Lookup(String key)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key of the setting.

Returns
object object object

The value, if an item with the specified key exists. Use the HasKey method to determine whether the key exists.

Attributes

Remarks

For a code example of Lookup, see the HasKey example.

See Also

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 Boolean
Parameters
key
TKey TKey TKey

The key of the element to remove.

Returns
System.Boolean System.Boolean System.Boolean

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.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

System.NotSupportedException System.NotSupportedException System.NotSupportedException

The System.Collections.Generic.IDictionary`2 is read-only.

See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

Remove(String) Remove(String) Remove(String)

Removes the specified application setting.

public void Remove(String key)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key of the setting.

Attributes

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)

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 Boolean
Parameters
key
TKey TKey TKey

The key whose value to get.

value
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.

Returns
System.Boolean System.Boolean System.Boolean

true if the object that implements System.Collections.Generic.IDictionary`2 contains an element with the specified key; otherwise, false.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

Events

MapChanged MapChanged MapChanged

Occurs when the map changes.

public event MapChangedEventHandler MapChangedpublic event MapChangedEventHandler MapChangedPublic Event MapChanged
Attributes

See Also