C# trigger windows 10 media notification

Viewed 248

How can I implement these Windows 10 "media notifications" into a C# WPF desktop application?

enter image description here

1 Answers

You are talking about the SystemMediaTransportControls class. Its usage it described on Microsoft Docs.

However, this API is designed for UWP so getting this to work in a regular desktop application like WPF takes a little more work. There are some answers here on StackOverflow that describe how to do this, but there is also some newer, official documentation from Microsoft on how to use these WinRT APIs.

Unfortunately, the System Media Transport Controls API is not directly supported in Desktop apps [5], so it gets a little more complicated, as described here [6].


In short, for .NET 5:

  1. Install the Windows 10 SDK of a version you like (e.g. through the VS Installer);

  2. Change the target framework to the SDK version you installed, e.g. net5.0-windows10.0.19041.0.

  3. Use the API interops as described on [6] to get an instance.

    In the case of SMTP, you'd want to use Windows.Media.SystemMediaTransportControlsInterop. This requires the handle to a window, which you can get with WindowInteropHelper in WPF.

  4. Use the SystemMediaTransportControls instance as described on [2].

Related