ApplicationDataContainerSettings ApplicationDataContainerSettings ApplicationDataContainerSettings ApplicationDataContainerSettings Class

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

Syntax

Declaration

public sealed class ApplicationDataContainerSettingspublic sealed class ApplicationDataContainerSettingsPublic NotInheritable Class ApplicationDataContainerSettings

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 summary

Gets the number of related application settings.

Methods summary

Removes all related application settings.

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

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

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

Inserts or replaces an application setting.

Retrieves the specified application setting.

Removes the specified application setting.

Events summary

Occurs when the map changes.

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 uint

    Property Value

    • uint
      uint
      uint
      uint

      The number of related settings.

Methods

  • Clear()
    Clear()
    Clear()
    Clear()

    Removes all related application settings.

    public void Clear()public void Clear()Public Function Clear() As void
  • 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 )

    Returns

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

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

    Returns

    • 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(System.String)
    HasKey(System.String)
    HasKey(System.String)
    HasKey(System.String)

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

    public bool HasKey(System.String key)public bool HasKey(System.String key)Public Function HasKey(key As System.String) As bool

    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.

    Remarks

    Examples

    Call the CreateContainer(System.String,Windows.Storage.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(System.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(System.String,System.Object)
    Insert(System.String,System.Object)
    Insert(System.String,System.Object)
    Insert(System.String,System.Object)

    Inserts or replaces an application setting.

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

    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.

  • Lookup(System.String)
    Lookup(System.String)
    Lookup(System.String)
    Lookup(System.String)

    Retrieves the specified application setting.

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

    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.

    Remarks

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

  • Remove(System.String)
    Remove(System.String)
    Remove(System.String)
    Remove(System.String)

    Removes the specified application setting.

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

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key of the setting.

    Remarks

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

Events

  • MapChanged
    MapChanged
    MapChanged
    MapChanged

    Occurs when the map changes.

    public event MapChangedEventHandler MapChangedpublic event MapChangedEventHandler MapChangedPublic Event MapChanged

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.Storage.dll