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 執行階段資料類型。