WidgetManager.DeleteWidget(String) Method

Definition

Requests the removal of a widget from the widget host.

public:
 virtual void DeleteWidget(Platform::String ^ widgetId) = DeleteWidget;
void DeleteWidget(winrt::hstring const& widgetId);
public void DeleteWidget(string widgetId);
function deleteWidget(widgetId)
Public Sub DeleteWidget (widgetId As String)

Parameters

widgetId
String

Platform::String

winrt::hstring

The unique identifier of the widget to remove. The widget ID value is dynamically generated by the WidgetManager. The widget ID remains the same for a widget from the moment of its creation until the moment the Widget is deleted. The widget ID is a unique value across all widgets and all widget providers.

Implements

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

Examples

The following example deletes all of the widgets with a specified .

/*
* Sample output:
* Deleted Widget with Id: {D8FEC89F-9A89-44B1-A52D-F04C515B0141}
*/
using namespace std;
using namespace winrt;

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

        for (const auto& widgetInfo : widgetInfos)
        {
            if (widgetInfo.WidgetContext().DefinitionName() == L"clockWidget")
            {
                hstring widgetId = widgetInfo.WidgetContext().Id();
                widgetManager.DeleteWidget(widgetId);

                wcout << L"Deleted Widget with Id: " << widgetId << endl;
            }
        }
    }
}

Remarks

After this method has been called, your provider will receive a notification that the widget has been deleted through the DeleteWidget(String, String) method.

Calling this method with the ID of a widget that has already been deleted will have no effect.

Applies to