Freigeben über


IPropertySet Schnittstelle

Definition

Stellt eine Auflistung von Schlüssel-Wert-Paaren dar, die mehrere andere Auflistungsschnittstellen korrelieren.

public interface class IPropertySet : IIterable<IKeyValuePair<Platform::String ^, Platform::Object ^> ^>, IMap<Platform::String ^, Platform::Object ^>, IObservableMap<Platform::String ^, Platform::Object ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.FoundationContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(2319707551, 62694, 17441, 172, 249, 29, 171, 41, 134, 130, 12)]
/// [Windows.Foundation.Metadata.HasVariant]
struct IPropertySet : IIterable<IKeyValuePair<winrt::hstring, IInspectable const&>>, IMap<winrt::hstring, IInspectable const&>, IObservableMap<winrt::hstring, IInspectable const&>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.FoundationContract), 65536)]
[Windows.Foundation.Metadata.Guid(2319707551, 62694, 17441, 172, 249, 29, 171, 41, 134, 130, 12)]
[Windows.Foundation.Metadata.HasVariant]
public interface IPropertySet : IDictionary<string,object>, IEnumerable<KeyValuePair<string,object>>, IObservableMap<string,object>
Public Interface IPropertySet
Implements IDictionary(Of String, Object), IEnumerable(Of KeyValuePair(Of String, Object)), IObservableMap(Of String, Object)
Abgeleitet
Attribute
Implementiert
IMap<K,V> IDictionary<K,V> IDictionary<String,Object> IMap<Platform::String,Platform::Object> IMap<winrt::hstring,IInspectable> IIterable<IKeyValuePair<K,V>> IEnumerable<KeyValuePair<K,V>> IEnumerable<KeyValuePair<String,Object>> IIterable<IKeyValuePair<Platform::String,Platform::Object>> IIterable<IKeyValuePair<winrt::hstring,IInspectable>> IObservableMap<String,Object> IObservableMap<Platform::String,Platform::Object> IObservableMap<winrt::hstring,IInspectable>

Windows-Anforderungen

Gerätefamilie
Windows 10 (eingeführt in 10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (eingeführt in v1.0)

Beispiele

In diesem Beispiel wird gezeigt, wie Sie nach einem Element innerhalb des IPropertySet-Objekts suchen, das von einer Windows-Runtime-Eigenschaft zurückgegeben wird. Dies stammt insbesondere aus der CoreApplication.Properties-Eigenschaft. Dieser Codeausschnitt stammt aus dem ControlChannelTrigger HTTP-Clientbeispiel. Beachten Sie, wie die C#-Version in IDictionary<Zeichenfolge,Objekt>, sodass sie den Indexer verwenden kann, während die Visual C++-Komponentenerweiterungen (C++/CX) HasKey und Lookupverwendet. In der Regel verwenden Sie ein IPropertySet-Objekt, das Sie aus den verschiedenen Windows-Runtime-Eigenschaften abrufen, die den Typ zurückgeben: Suchen Sie nach bestimmten Schlüsseln im Eigenschaftensatz, und legen Sie dann einige App-Eigenschaft auf den entsprechenden Wert fest, falls vorhanden.

// In this example, the channel name has been hardcoded to lookup the property bag 
// for any previous contexts. The channel name may be used in more sophisticated ways 
// in case an app has multiple ControlChannelTrigger objects. 
string channelId = "channelOne";
if (((IDictionary<string, object>)CoreApplication.Properties).ContainsKey(channelId))
{
    try
    {
        AppContext appContext = null;
        lock(CoreApplication.Properties)
        {
            appContext = ((IDictionary<string, object>)CoreApplication.Properties)[channelId] as AppContext;
        }
        if (appContext != null && appContext.CommunicationInstance != null)
        {
            CommunicationModule communicationInstance = appContext.CommunicationInstance;

            // Clear any existing channels, sockets etc. 
            communicationInstance.Reset();

            // Create CCT enabled transport. 
            communicationInstance.SetUpTransport(communicationInstance.serverUri, GetType().Name);
        }
    }
    catch (Exception ex)
    {
        Diag.DebugPrint("Registering with CCT failed with: " + ex.ToString());
    }
}
else
{
    Diag.DebugPrint("Cannot find AppContext key channelOne");
}
// In this example, the channel name has been hardcoded to look up the property bag
// for any previous contexts. The channel name may be used in more sophisticated ways
// in case an app has multiple ControlChannelTrigger objects.
std::wstring channelId{ L"channelOne" };
if (CoreApplication::Properties().HasKey(channelId))
{
    try
    {
        auto appContext{ CoreApplication::Properties().Lookup(channelId).as<AppContext>() };
        if (appContext && appContext->CommunicationInstance())
        {
            CommunicationModule communicationInstance{ appContext->CommunicationInstance() };

            // Clear any existing channels, sockets etc.
            communicationInstance.Reset();

            // Create CCT enabled transport.
            communicationInstance.SetUpTransport(L"NetworkChangeTask");
        }
    }
    catch (winrt::hresult_error const& ex)
    {
        Diag::DebugPrint(L"Registering with CCT failed with: " + ex.message());
    }
}
else
{
    Diag::DebugPrint(L"Cannot find AppContext key channelOne");
}
// In this example, the channel name has been hardcoded to look up the property bag
// for any previous contexts. The channel name may be used in more sophisticated ways
// in case an app has multiple ControlChannelTrigger objects.
String^ channelId = "channelOne";
if (CoreApplication::Properties->HasKey(channelId))
{
    try
    {
        auto appContext = dynamic_cast<AppContext^>(CoreApplication::Properties->Lookup(channelId));
        if (appContext != nullptr && appContext->CommunicationInstance != nullptr)
        {
            CommunicationModule^ communicationInstance = appContext->CommunicationInstance;

            // Clear any existing channels, sockets etc. 
            communicationInstance->Reset();

            // Create CCT enabled transport 
            communicationInstance->SetUpTransport("NetworkChangeTask");
        }
    }
    catch (Exception^ ex)
    {
        Diag::DebugPrint("Registering with CCT failed with: " + ex->Message);
    }
}
else
{
    Diag::DebugPrint("Cannot find AppContext key channelOne");
}

Hinweise

Diese Schnittstelle ist ungewöhnlich, da keine neuen Member definiert werden. Stattdessen korreliert sie drei andere Sammlungsschnittstellen, sodass sie dieselben Typparametereinschränkungen verwenden:

Wenn Sie ein Objekt in IPropertySet umwandeln (was nicht generisch ist), können Sie die kombinierten Methoden dieser drei Schnittstellen basierend auf der Verwendung von String für Schlüssel verwenden, Object für wert. Für eine praktische Implementierung verwendet Windows-Runtime die klasse PropertySet. In der Dokumentation finden Sie verschiedene Member von PropertySet-, um zu erfahren, wie Sie diese Methoden verwenden, sobald Sie als IPropertySet umwandeln.

In vielen Fällen, in denen eine Windows-Runtime-API ein PropertySet- als Wert verwendet, wird es tatsächlich als IPropertySet in den Signaturen angezeigt. PropertySet- kann als praktische Implementierung von IPropertySet betrachtet werden, die für die Verwendung durch App-Code bereit ist. JavaScript-Code kann jeden IPropertySet-Wert so behandeln, als ob er die PropertySet Prototypen implementiert. Die Verwendung nach Typ ist das Hauptszenario für IPropertySet; Tatsächlich ist die Implementierung der Schnittstelle in Ihrem App-Code weniger häufig.

IPropertySet wird auch von der ValueSet Klasse implementiert. ValueSet- ist der Werttyp mehrerer ContinuationData--Eigenschaften, die das Wiederherstellen des Zustands ermöglichen, wenn Apps nach dem Aufrufen einer AndContinue--Methode fortgesetzt werden, die die App möglicherweise deaktiviert. ValueSet und alle ContinuationData Eigenschaften und AndContinue- Methoden sind nur APIs Windows Phone, da es nur Windows Phone ist, die dieses Verhalten aufweisen. Weitere Informationen finden Sie unter Fortsetzen Ihrer Windows Phone Store-App nach dem Aufrufen einer AndContinue-Methode. Der Unterschied zwischen ValueSet- und PropertySet- besteht darin, dass die ValueSet Implementierung von Methoden wie Insert erzwingt, dass ihre Eigenschaftswerte Werttypen sind.

Ereignisse

MapChanged

Tritt auf, wenn sich die Karte ändert.

(Geerbt von IObservableMap<K,V>)

Gilt für:

Weitere Informationen