Adding Windows 11 Widgets to a UWP Application

With the recent release of v1.2 of the Windows App SDK came support for developing third party widgets for Windows 11. What’s not immediately obvious from the documentation is that you don’t have to be using Windows UI (WinUI), or even the Windows App SDK, for your application. In this post we’re going to add a widget to a UWP application, meaning you don’t need to re-write your application in order to pair it with a companion widget.

For reference, here’s my previous post covering Adding a Windows Widget to a C# Windows App SDK (Windows UI) App and the source code for this post.

Widget Implementation

The main difference with the widget implementation is that rather than including the code in the same project as the application, we need to create a separate project for the widget code. The widget provider implementation relies on the APIs that are only available in the Windows App SDK and it’s not possible to add the Windows App SDK to a UWP application.

We’ll create a new project based on the Class Library project template and update the csproj to the following:

<Project Sdk="Microsoft.NET.Sdk">

		<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.221116.1" />
		<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />

		<Content Include="ProviderAssets\Counting_Icon.png" />
		<Content Include="ProviderAssets\Counting_Screenshot.png" />
		<Content Include="Templates\MultiplyingWidgetTemplate.json" />

		<ProjectReference Include="..\COMHelpers\COMHelpers.csproj" />
		<ProjectReference Include="..\WidgetHelpers\WidgetHelpers.csproj" />


As with the previous post there’s a reference to the COM Server (in the COMHelpers project) and the IWidget, WidgetBase and WidgetProviderBase (in the WidgetHelpers project). This means we can focus on the implementation of our widget as follows:

Multiplying Widget

internal class MultiplyingWidget : WidgetBase
    private const int StartingNumber = 1;
    private int _clickCount = StartingNumber;

    public override string State { 
        get => base.State;
        set {
            base.State = value;
            if (string.IsNullOrWhiteSpace(value))
                State = StartingNumber.ToString();
                    // This particular widget stores its clickCount
                    // in the state as integer. Attempt to parse the saved state
                    // and convert it to integer.
                    _clickCount = int.Parse(value);
                    // Parsing the state was not successful: cached state might've been corrupted.
                    State = StartingNumber.ToString();

    // This function wil be invoked when the Multiply button was clicked by the user.
    public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs)
        var verb = actionInvokedArgs.Verb;
        if (verb == "multiply")
            // Decrement the count
            State = _clickCount + "";

            // Generate template/data you want to send back
            // The template has not changed so it does not neeed to be updated
            var widgetData = GetDataForWidget();

            // Build update options and update the widget
            WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(Id);
            updateOptions.Data = widgetData;
            updateOptions.CustomState = State;


    public override string GetTemplateForWidget()
        // This widget has the same template for all the sizes/themes so we load it only once.
        var widgetTemplate = GetTemplateFromFile("ms-appx:///MyUWPWidget/Templates/MultiplyingWidgetTemplate.json");
        return widgetTemplate;

    public override string GetDataForWidget()
        return "{ \"count\": " + State + " }";


internal class WidgetProvider:WidgetProviderBase
    static WidgetProvider()

Note that we’ve changed the GUID for this widget provider to make sure it’s unique.

The last part of the widget implementation is to add a Program.cs file with the following code.

public class Program
    static async Task Main(string[] args)

        if (args?.Any(x => x.Contains("RegisterProcessAsComServer")) ?? false)
            ComServer<IWidgetProvider, WidgetProvider>.Instance.Run();

UWP Packaging

Now that we have our widget implementation, we need to package the widget alongside our UWP application. Since we can’t add a reference to the widget project to our UWP application, we need to change the UWP application to use a separate packaging project.

Create a new project based on the Windows Application Packaging Project template.

Add a project reference to the UWP application and then build and run the packaging project – make sure you’re able to build, run and debug your UWP application before proceeding. Note that you’ll need to update the package.appxmanifest in the packaging project with the details of the UWP application, since the package.appxmanfiest in the UWP project will no longer be used.

Next, you’ll need to add a reference to the Windows App SDK and the build tools to the packaging project. This can be done by adding the following ItemsGroup to the csproj file directly and rebuilding the project.

		<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.221109.1">
		<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755">

Now you can add a reference to the project that contains the widget implementation and update the package.appxmanifest to include the extensions that define the widget provider and the widget types.

<?xml version="1.0" encoding="utf-8"?>
	IgnorableNamespaces="uap uap3 rescap">

    Version="" />


    <TargetDeviceFamily Name="Windows.Universal" MinVersion="" MaxVersionTested="" />
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />

    <Resource Language="x-generate"/>

    <Application Id="App"
        <uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
        <uap:SplashScreen Image="Images\SplashScreen.png" />
			<com:Extension Category="windows.comServer">
					<com:ExeServer Executable="MyUWPWidget/MyUWPWidget.exe" Arguments="-RegisterProcessAsComServer" DisplayName="MyUWPWidget">
						<com:Class Id="29B1E7D7-1CD0-4713-BE54-BBD29F86E8B1" DisplayName="MyUWPWidgetProvider" />
			<uap3:Extension Category="windows.appExtension">
				<uap3:AppExtension Name="" DisplayName="MyUWPWidget" Id="MyUWPWidget" PublicFolder="Public">
								<Icon Path="Images\StoreLogo.png" />
								<CreateInstance ClassId="29B1E7D7-1CD0-4713-BE54-BBD29F86E8B1" />
								<Definition Id="Multiplying"
									DisplayName="Sample Multiplying Widget"
									Description="Multiplying Widget Description">
											<Size Name="small" />
											<Size Name="medium" />
											<Size Name="large" />
											<Icon Path="ProviderAssets\Counting_Icon.png" />
											<Screenshot Path="ProviderAssets\Counting_Screenshot.png" DisplayAltText="For accessibility" />
										<!-- DarkMode and LightMode are optional -->
										<DarkMode />
										<LightMode />


    <Capability Name="internetClient" />
    <rescap:Capability Name="runFullTrust" />


You can debug this widget the same way as we did in the previous post by preventing Visual Studio from launching the application when you press F5/Run. Note that this option needs to be set on the packaging project, and since this uses the old style project properties, the option is found on the Debug tab.

And there you have it – a widget that’s associated with your UWP application.

Leave a comment