Bagikan melalui


ApplicationData.LocalSettings Properti

Definisi

Mendapatkan kontainer pengaturan aplikasi di penyimpanan data aplikasi lokal.

public:
 property ApplicationDataContainer ^ LocalSettings { ApplicationDataContainer ^ get(); };
ApplicationDataContainer LocalSettings();
public ApplicationDataContainer LocalSettings { get; }
var applicationDataContainer = applicationData.localSettings;
Public ReadOnly Property LocalSettings As ApplicationDataContainer

Nilai Properti

Kontainer pengaturan aplikasi.

Contoh

Gunakan properti LocalSettings untuk mendapatkan pengaturan di objek ApplicationDataContainer . Gunakan properti ApplicationDataContainer.Values untuk mengakses pengaturan dalam localSettings kontainer. Contoh ini membuat dan membaca pengaturan bernama exampleSetting.

Panggil metode ApplicationDataContainerSettings.Remove untuk menghapus exampleSetting pengaturan setelah Anda selesai menggunakannya.

Perhatikan bahwa untuk mengakses RoamingSettings, gunakan proses yang sama yang diuraikan dalam contoh, kecuali mengubah kemunculan localSettings menjadi 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")

Keterangan

Untuk LocalSettings dan RoamingSettings, panjang nama setiap pengaturan paling banyak 255 karakter. Setiap pengaturan dapat berukuran hingga 8K byte dan setiap pengaturan komposit dapat berukuran hingga 64K byte.

Jenis data Windows Runtime didukung untuk pengaturan aplikasi.

Berlaku untuk

Lihat juga