ApplicationDataContainer 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示應用程式設定的容器。 這個類別的方法和屬性支援建立、刪除、列舉和周遊容器階層。
public ref class ApplicationDataContainer sealed
public ref class ApplicationDataContainer sealed : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ApplicationDataContainer final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ApplicationDataContainer final : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ApplicationDataContainer
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ApplicationDataContainer : System.IDisposable
Public NotInheritable Class ApplicationDataContainer
Public NotInheritable Class ApplicationDataContainer
Implements IDisposable
- 繼承
- 屬性
- 實作
Windows 需求
裝置系列 |
Windows 10 (已於 10.0.10240.0 引進)
|
API contract |
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
|
範例
呼叫 ApplicationDataContainer.CreateContainer 方法來建立設定容器,或傳回現有的容器。 此範例會建立名為 的 exampleContainer
設定容器,並新增名為 的 exampleSetting
設定。 ApplicationDataCreateDisposition列舉中的Always值表示如果容器不存在,就應該建立容器。
使用 ApplicationDataContainer.Values 屬性來存取 exampleSetting
容器中的 exampleContainer
設定。
呼叫 ApplicationDataContainer.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");
Windows::Storage::ApplicationDataContainer localSettings{
Windows::Storage::ApplicationData::Current().LocalSettings() };
// Create a setting in a container.
Windows::Storage::ApplicationDataContainer container{
localSettings.CreateContainer(L"exampleContainer", Windows::Storage::ApplicationDataCreateDisposition::Always) };
if (localSettings.Containers().HasKey(L"exampleContainer"))
{
auto values{ localSettings.Containers().Lookup(L"exampleContainer").Values() };
values.Insert(L"exampleSetting", winrt::box_value(L"Hello, Windows!"));
}
// Read data from a setting in a container.
bool hasContainer{ localSettings.Containers().HasKey(L"exampleContainer") };
bool hasSetting{ false };
if (hasContainer)
{
auto values{ localSettings.Containers().Lookup(L"exampleContainer").Values() };
hasSetting = values.HasKey(L"exampleSetting");
}
// Delete a container.
localSettings.DeleteContainer(L"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");
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")
備註
注意
暫存應用程式資料存放區沒有設定容器。
Values屬性會取得ApplicationDataContainerSettings物件,該物件可讓您存取儲存在容器中的設定。
屬性
Containers |
取得這個應用程式設定容器的子應用程式設定容器。 |
Locality |
取得與目前設定容器相關聯之應用程式資料存放區 (本機或漫遊) 類型。 |
Name |
取得目前設定容器的名稱。 |
Values |
取得 物件,表示這個設定容器中的設定。 |
方法
Close() |
注意 此成員未在 C# 中實作。 |
CreateContainer(String, ApplicationDataCreateDisposition) |
在目前的設定容器中建立或開啟指定的設定容器。 |
DeleteContainer(String) |
刪除指定的設定容器、其子容器,以及階層中的所有應用程式設定。 |
Dispose() |
執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。 |