다음을 통해 공유


WidgetManager.GetWidgetInfos 메서드

정의

호출 앱과 연결된 모든 위젯에 대한 저장된 정보를 가져옵니다.

public:
 virtual Platform::Array <WidgetInfo ^> ^ GetWidgetInfos() = GetWidgetInfos;
winrt::array_view <WidgetInfo const&> GetWidgetInfos();
public WidgetInfo[] GetWidgetInfos();
function getWidgetInfos()
Public Function GetWidgetInfos () As WidgetInfo()

반환

연결된 위젯에 대한 정보를 포함하는 개체의 WidgetInfo 배열입니다.

구현

예제

다음 코드 예제에서는 호출 앱이 소유한 모든 위젯에 대한 정보를 검색하는 방법을 보여 줍니다. 이 예제에서는 하루 이상 업데이트되지 않은 위젯을 업데이트합니다.

using namespace std;
using namespace winrt;
using namespace Windows::Foundations;
using namespace Microsoft::Windows::Widgets;
using namespace Microsoft::Windows::Widgets::Providers;

class WidgetManagerOperations
{
    void UpdateWidgetsWith24HourOutdate()
    {
        com_array<WidgetInfo> widgetInfos = WidgetManager::GetDefault().GetWidgetInfos();

        for (const auto widgetInfo : widgetInfos)
        {
            if (widgetInfo.WidgetContext().DefinitionName() == L"clockWidget")
            {
                auto diffInSeconds = static_cast<long long int>(clock::to_time_t(end), clock::to_time_t(beginning));
                auto diffInDays = (((diffInSeconds / 60) / 60) / 24);

                if (diffInDays >= 1)
                {
                    WidgetUpdateRequestOptions options{widgetInfo.WidgetContext().Id()};
                    options.Template(LR"({
                        "type": "AdaptiveCard",
                        "version": "1.5",
                        "body": [
                            {
                                "type": "TextBlock",
                                "text": "Today is: ${date}"
                            }
                        ]
                    })");

                    options.Data(LR"({
                        "date": "05-23-2022"
                    })");

                    widgetManager.UpdateWidget(options);
                }
            }
        }
    }
}

적용 대상