ApplicationData.LocalSettings 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取本地应用数据存储中的应用程序设置容器。
public:
property ApplicationDataContainer ^ LocalSettings { ApplicationDataContainer ^ get(); };
ApplicationDataContainer LocalSettings();
public ApplicationDataContainer LocalSettings { get; }
var applicationDataContainer = applicationData.localSettings;
Public ReadOnly Property LocalSettings As ApplicationDataContainer
属性值
应用程序设置容器。
示例
使用 LocalSettings 属性获取 ApplicationDataContainer 对象中的设置。 使用 ApplicationDataContainer.Values 属性访问容器中的 localSettings
设置。 此示例创建并读取名为 的设置 exampleSetting
。
调用 ApplicationDataContainerSettings.Remove 方法以 exampleSetting
在完成设置后将其删除。
请注意,若要访问 RoamingSettings,请使用示例中概述的相同过程,但将 的 localSettings
匹配项更改为 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")
注解
对于 LocalSettings 和 RoamingSettings,每个设置的名称长度最多可以为 255 个字符。 每个设置的大小最多可为 8K 字节,每个复合设置的大小最多可为 64K 字节。
应用设置支持Windows 运行时数据类型。