Compartir a través de


WidgetManager.GetWidgetInfo(String) Método

Definición

Obtiene un WidgetInfo objeto que contiene información sobre el widget con el identificador de widget proporcionado, incluida la plantilla visual, la plantilla de datos, el estado personalizado, la hora de la última actualización y la información de contexto del host del widget.

public:
 virtual WidgetInfo ^ GetWidgetInfo(Platform::String ^ widgetId) = GetWidgetInfo;
WidgetInfo GetWidgetInfo(winrt::hstring const& widgetId);
public WidgetInfo GetWidgetInfo(string widgetId);
function getWidgetInfo(widgetId)
Public Function GetWidgetInfo (widgetId As String) As WidgetInfo

Parámetros

widgetId
String

Platform::String

winrt::hstring

Identificador único del widget para el que se recupera información.

Devoluciones

Un objeto WidgetInfo , si el identificador especificado está asociado a un widget asociado a la aplicación que realiza la llamada que no se ha eliminado; de lo contrario, null.

Implementaciones

M:Microsoft.Windows.Widgets.Providers.IWidgetManager.GetWidgetInfo(System.String) M:Microsoft.Windows.Widgets.Providers.IWidgetManager.GetWidgetInfo(Platform::String) M:Microsoft.Windows.Widgets.Providers.IWidgetManager.GetWidgetInfo(winrt::hstring)

Ejemplos

En el ejemplo siguiente se muestra cómo recuperar información del widget para uno de los widgets que pertenecen a la aplicación que realiza la llamada.

/*
* Sample output:
* Id: {5E3D9EDF-13A6-4185-902B-5997AE0411A5}
* Template: {
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.5"
    "body": [
        {
            "type": "TextBlock",
            "text": "${greeting}!"
        }
    ]
}
* Data: {"count": "3"}
* CustomState: 3
* DefinitionName: clickCounter
*/
using namespace std;
using namespace winrt;
using namespace Microsoft::Windows::Widgets::Providers;

class WidgetManagerOperations
{
    void PrintInfoOfWidget(hstring myWidgetId)
    {
        WidgetManager widgetManager = WidgetManager::GetDefault();

        WidgetInfo widgetInfo = widgetManager.GetWidgetInfo(myWidgetId);
        wcout << L"Id - " << L": " << widgetInfo.WidgetContext().Id().c_str() << endl;
        wcout << L"Template: " << widgetInfo.Template().c_str() << endl;
        wcout << L"Data: " << widgetInfo.Data().c_str() << endl;
        wcout << L"CustomState: " << widgetInfo.CustomState().c_str() << endl;
        wcout << L"DefinitionName: " << widgetInfo.WidgetContext().DefinitionName().c_str() << endl;
    }
}

Comentarios

Los proveedores de widgets pueden usar este método al controlar una solicitud asociada a un widget no reconocido para recuperar el último estado conocido. Por ejemplo, si almacena los estados de los widgets en la WidgetUpdateRequestOptions.CustomState propiedad , puede usar este método durante la inicialización del proveedor del widget para volver a generar el estado de los widgets.

Se aplica a