VirtualDesktop wraps the Windows shell's virtual desktop API for desktop apps. Microsoft's IVirtualDesktopManager reference
- Look up the desktop for a top-level window and check whether it is on the current desktop.
- Move a window owned by the calling process to a known desktop.
- Observe changes to the current desktop.
Install NuGet package(s).
PM> Install-Package VirtualDesktop- VirtualDesktop - Core classes for VirtualDesktop.
- VirtualDesktop.WPF - Provides extension methods for WPF Window class.
- VirtualDesktop.WinForms - Provides extension methods for Form class.
Preparation:
<!-- Please create application manifest file and run without debugging. -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>using WindowsDesktop;Query a window's desktop
var desktop = VirtualDesktop.FromHwnd(hwnd);
var isCurrent = VirtualDesktop.IsWindowOnCurrentVirtualDesktop(hwnd);Callers migrating from TryGetIdFromHwnd can use IdFromHwnd to get a nullable GUID. During an Explorer restart, both queries can return null. The Boolean IsCurrentVirtualDesktop helper returns false in that case. If Windows has no registered virtual desktop manager, IsPresent returns false and queries for a window throw NotSupportedException. Other shell failures propagate as managed exceptions.
CurrentID returns Guid.Empty until the library identifies a desktop. Subscribe to CurrentChanged and then read CurrentID to cover both startup and later changes. The first observation has a null OldDesktop. UI subscribers receive events on their subscribing synchronization context. Subscribers without a context receive them on the listener thread.
for WPF window
// Need to install 'VirtualDesktop.WPF' package
// Check whether a window is on the current desktop.
var isCurrent = window.IsCurrentVirtualDesktop();
// Get Virtual Desktop for WPF window
var desktop = window.GetCurrentDesktop();
// Move window to specific Virtual Desktop
window.MoveToDesktop(desktop);See also:
- samples/VirtualDesktop.Showcase project

This library is under the MIT License.