IPropertySet Schnittstelle

Definition

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

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 im IPropertySet-Objekt nach einem Element suchen, das von einer Windows-Runtime-Eigenschaft zurückgegeben wird. Insbesondere stammt dies von der CoreApplication.Properties-Eigenschaft . Dieser Codeausschnitt stammt aus dem Http-Clientbeispiel "ControlChannelTrigger". Beachten Sie, wie die C#-Version in die IDictionary-Zeichenfolge<,Object> umgewandelt wird, damit sie den Indexer verwenden kann, während die Visual C++/CX-Version (Visual C++/CX) HasKey und Lookup verwendet. In der Regel ist dies alles, was Sie mit einem IPropertySet-Objekt tun, 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 eine 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 insofern ungewöhnlich, als sie keine neuen Member definiert. Stattdessen korreliert sie drei andere Sammlungsschnittstellen, sodass sie dieselben Typparametereinschränkungen aufweisen:

Wenn Sie ein Objekt in IPropertySet umwandeln (was kein generisches Element ist), können Sie die kombinierten Methoden dieser drei Schnittstellen basierend auf der Verwendung von String für Schlüssel, Object for value verwenden. Für eine praktische Implementierung verwendet Windows-Runtime die PropertySet-Klasse. In der Dokumentation für verschiedene Elemente von PropertySet erfahren Sie, wie Sie diese Methoden verwenden, sobald Sie als IPropertySet umgewandelt wurden.

In vielen Fällen, in denen eine Windows-Runtime-API ein PropertySet als Wert verwendet, wird sie 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 hätte. Die Verwendung nach Typ ist das Standard Szenario für IPropertySet. Die Tatsächliche Implementierung der Schnittstelle in Ihrem App-Code ist weniger üblich.

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 Windows Phone APIs, da dieses Verhalten nur Windows Phone aufweist. 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