VirtualDesktop is C# wrapper for IVirtualDesktopManager on Windows 10 / 11.
- Switch, add, and remove a virtual desktop.
- Move the window in the same process to any virtual desktop.
- Move the window of another process to any virtual desktop (Support in version 2.0 or later).
- Pin any window or application; will be display on all desktops.
- Notification for switching, deletion, renaming, etc.
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 / 11-->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
using WindowsDesktop;
Get instance of VirtualDesktop class:
// Get all virtual desktops
var desktops = VirtualDesktop.GetDesktops();
// Get Virtual Desktop for specific window
var desktop = VirtualDesktop.FromHwnd(hwnd);
// Get the left/right desktop
var left = desktop.GetLeft();
var right = desktop.GetRight();
Manage virtual desktops:
// Create new
var desktop = VirtualDesktop.Create();
// Remove
desktop.Remove();
// Switch
desktop.GetLeft().Switch();
Virtual desktop events:
// Notification of desktop switching
VirtualDesktop.CurrentChanged += (_, args) => Console.WriteLine($"Switched: {args.NewDesktop.Name}");
// Notification of desktop creating
VirtualDesktop.Created += (_, desktop) => desktop.Switch();
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);
// Pin window
window.Pin()
See also:
- samples/VirtualDesktop.Showcase project
This library is under the MIT License.