ApplicationData.LocalSettings Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the application settings container in the local app data store.
public:
property ApplicationDataContainer ^ LocalSettings { ApplicationDataContainer ^ get(); };
ApplicationDataContainer LocalSettings();
public ApplicationDataContainer LocalSettings { get; }
var applicationDataContainer = applicationData.localSettings;
Public ReadOnly Property LocalSettings As ApplicationDataContainer
Property Value
The application settings container.
Examples
Use the LocalSettings property to get the settings in an ApplicationDataContainer object. Use the ApplicationDataContainer.Values property to access the settings in the localSettings
container. This example creates and reads a setting named exampleSetting
.
Call the ApplicationDataContainerSettings.Remove method to delete the exampleSetting
setting when you have finished with it.
Note that to access the RoamingSettings, use the same process outlined in the example, except change the occurrences of localSettings
to roamingSettings
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a simple setting.
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting.
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data.
}
else
{
// Access data in value.
}
// Delete a simple setting.
localSettings.Values.Remove("exampleSetting");
Windows::Storage::ApplicationDataContainer localSettings{
Windows::Storage::ApplicationData::Current().LocalSettings() };
// Create a simple setting.
auto values{ localSettings.Values() };
values.Insert(L"exampleSetting", Windows::Foundation::PropertyValue::CreateString(L"Hello Windows"));
// Read data from a simple setting.
winrt::hstring value{ winrt::unbox_value<winrt::hstring>(values.Lookup(L"exampleSetting")) };
// Access data in value.
// Delete a simple setting.
values.Remove(L"exampleSetting");
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
// Create a simple setting.
auto values = localSettings->Values;
values->Insert("exampleSetting", dynamic_cast<PropertyValue^>(PropertyValue::CreateString("Hello Windows")));
// Read data from a simple setting.
String^ value = safe_cast<String^>(values->Lookup("exampleSetting"));
if (!value)
{
// No data.
}
else
{
// Access data in value.
}
// Delete a simple setting.
values->Remove("exampleSetting");
Dim localSettings As Windows.Storage.ApplicationDataContainer = Windows.Storage.ApplicationData.Current.LocalSettings
' Create a simple setting
localSettings.Values("exampleSetting") = "Hello Windows";
' Read data from a simple setting
Dim value As Object = localSettings.Values("exampleSetting")
If value Is Nothing Then
' No data
Else
' Access data in value
End If
' Delete a simple setting
localSettings.Values.Remove("exampleSetting")
Remarks
For both LocalSettings and RoamingSettings, the name of each setting can be 255 characters in length at most. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size.
The Windows Runtime data types are supported for app settings.