VirtualDesktop 5.0.5

.NET 5.0
dotnet add package VirtualDesktop --version 5.0.5
NuGet\Install-Package VirtualDesktop -Version 5.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VirtualDesktop" Version="5.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VirtualDesktop --version 5.0.5
#r "nuget: VirtualDesktop, 5.0.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install VirtualDesktop as a Cake Addin
#addin nuget:?package=VirtualDesktop&version=5.0.5

// Install VirtualDesktop as a Cake Tool
#tool nuget:?package=VirtualDesktop&version=5.0.5

VirtualDesktop

VirtualDesktop is C# wrapper for IVirtualDesktopManager on Windows 11 (and Windows 10).

Build Nuget (with prereleases) License

Features

  • 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.
  • Change the wallpaper for each desktop.

Sample app

samples/VirtualDesktop.Showcase

Requirements

<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
  • .NET 5 or 6
  • Windows 10 build 19041 (20H1) or later

Installation

Install NuGet package(s).

PM> Install-Package VirtualDesktop

How to use

Preparation

Because of the dependency on C#/WinRT (repo), the target framework must be set to net5.0-windows10.0.19041.0 or later.

<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>

If it doesn't work, try creating an app.manifest file and optimize to work on Windows 10.

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
	    
	    <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
    </application>
</compatibility>

The namespace to use is WindowsDesktop.

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();

Subscribe 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:

License

This library is under the MIT License.

Product Versions
.NET net5.0-windows10.0.19041 net6.0-windows10.0.19041
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on VirtualDesktop:

Package Downloads
VirtualDesktop.WPF

C# Wrapper for the Virtual Desktop API on Windows 11 (and Windows 10).

VirtualDesktop.WinForms

C# Wrapper for the Virtual Desktop API on Windows 11 (and Windows 10).

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on VirtualDesktop:

Repository Stars
m0ngr31/VirtualDesktopManager
glsorre/amethystwindows
Automatic tiling window manager for Windows 10/11
Version Downloads Last updated
5.0.5 1,511 2/7/2022
5.0.4 238 2/6/2022
5.0.3 207 2/6/2022
5.0.2 211 2/6/2022
5.0.1 212 2/5/2022
5.0.0 221 2/5/2022
4.0.1 1,842 3/22/2020
4.0.0 795 3/22/2020
3.0.0-beta1 754 9/11/2018
2.0.0-beta3 3,679 8/6/2016
2.0.0-beta2 981 8/6/2016
2.0.0-beta 1,386 8/3/2016
1.0.3 3,148 12/15/2015
1.0.2 1,410 12/15/2015
1.0.1 1,076 12/15/2015
1.0.0 1,617 12/15/2015