WidgetManager.GetWidgetInfo(String) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient un WidgetInfo objet contenant des informations sur le widget avec l’ID de widget fourni, notamment le modèle visuel, le modèle de données, l’état personnalisé, l’heure de la dernière mise à jour et les informations de contexte de l’hôte du 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
Paramètres
- widgetId
-
String
Platform::String
winrt::hstring
Identificateur unique du widget pour lequel les informations sont récupérées.
Retours
Objet WidgetInfo , si l’ID spécifié est associé à un widget associé à l’application appelante qui n’a pas été supprimé ; sinon, null.
Implémente
Exemples
L’exemple suivant illustre la récupération des informations de widget pour l’un des widgets appartenant à l’application appelante.
/*
* 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;
}
}
Remarques
Cette méthode peut être utilisée par les fournisseurs de widgets lors de la gestion d’une requête associée à un widget non reconnu afin de récupérer le dernier état connu. Par exemple, si vous stockez les états de vos widgets dans la propriété, vous pouvez utiliser cette méthode lors de l’initialisation WidgetUpdateRequestOptions.CustomState de votre fournisseur de widgets pour régénérer l’état de vos widgets.