ApplicationDataContainerSettings ApplicationDataContainerSettings ApplicationDataContainerSettings ApplicationDataContainerSettings Class

Definition

Provides access to the settings in a settings container. The Values property returns an object that can be cast to this type.

public sealed class ApplicationDataContainerSettingspublic sealed class ApplicationDataContainerSettingsPublic NotInheritable Class ApplicationDataContainerSettingspublic sealed class ApplicationDataContainerSettings
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 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

Size Size Size Size

Gets the number of related application settings.

public uint Size { get; }public uint Size { get; }Public ReadOnly Property Size As uintpublic uint Size { get; }
Value
uint uint uint uint

The number of related settings.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Methods

Clear() Clear() Clear() Clear()

Removes all related application settings.

public void Clear()public void Clear()Public Function Clear() As voidpublic void Clear()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

First() First() First() First()

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

public IIterator<IKeyValuePair<string, object>> First()public IIterator<IKeyValuePair<string, object>> First()Public Function First() As IIterator( Of IKeyValuePairstring, object )public IIterator<IKeyValuePair<string, object>> First()
Returns

The iterator.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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.

GetView() GetView() GetView() GetView()

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

public IMapView<string, object> GetView()public IMapView<string, object> GetView()Public Function GetView() As IMapView( Of string, object )public IMapView<string, object> GetView()
Returns

The view of the settings container.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 bool HasKey(String key)public bool HasKey(String key)Public Function HasKey(key As String) As boolpublic bool HasKey(String key)
Parameters
key
System.String System.String System.String System.String

The key.

Returns
bool bool bool bool

True if the key is found; otherwise false.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

Examples

Call the CreateContainer(String, ApplicationDataCreateDisposition) 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 Values property to access the exampleSetting setting in the exampleContainer container.

Call the DeleteContainer(String) 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");

Insert(String, Object) Insert(String, Object) Insert(String, Object) Insert(String, Object)

Inserts or replaces an application setting.

public bool Insert(String key, Object value)public bool Insert(String key, Object value)Public Function Insert(key As String, value As Object) As boolpublic bool Insert(String key, Object value)
Parameters
key
System.String System.String System.String System.String

The key of the setting to insert or replace.

value
System.Object System.Object System.Object System.Object

The setting value.

Returns
bool bool bool bool

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

Retrieves the specified application setting.

public object Lookup(String key)public object Lookup(String key)Public Function Lookup(key As String) As objectpublic object Lookup(String key)
Parameters
key
System.String System.String System.String System.String

The key of the setting.

Returns
object object object object

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

For a code example of Lookup(String), see the HasKey(String) example.

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

Removes the specified application setting.

public void Remove(String key)public void Remove(String key)Public Function Remove(key As String) As voidpublic void Remove(String key)
Parameters
key
System.String System.String System.String System.String

The key of the setting.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

For the C# and Microsoft Visual Basic version of the Remove(String) method, see Remove(String).

Events

MapChanged MapChanged MapChanged MapChanged

Occurs when the map changes.

public event MapChangedEventHandler MapChangedpublic event MapChangedEventHandler MapChangedPublic Event MapChangedpublic event MapChangedEventHandler MapChanged
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)