Slions.VirtualDesktop.WinForms 6.9.2

Prefix Reserved
dotnet add package Slions.VirtualDesktop.WinForms --version 6.9.2
                    
NuGet\Install-Package Slions.VirtualDesktop.WinForms -Version 6.9.2
                    
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="Slions.VirtualDesktop.WinForms" Version="6.9.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Slions.VirtualDesktop.WinForms" Version="6.9.2" />
                    
Directory.Packages.props
<PackageReference Include="Slions.VirtualDesktop.WinForms" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Slions.VirtualDesktop.WinForms --version 6.9.2
                    
#r "nuget: Slions.VirtualDesktop.WinForms, 6.9.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Slions.VirtualDesktop.WinForms&version=6.9.2
                    
Install Slions.VirtualDesktop.WinForms as a Cake Addin
#tool nuget:?package=Slions.VirtualDesktop.WinForms&version=6.9.2
                    
Install Slions.VirtualDesktop.WinForms as a Cake Tool

VirtualDesktop

.NET library for Windows multiple desktop operations

Windows 11 Windows 10

Build Publish License

Platform NuGet Downloads
Core NuGet Badge NuGet Downloads
Forms NuGet Badge NuGet Downloads
WPF NuGet Badge NuGet Downloads

Features

  • Switch, add, and remove a virtual desktop
  • Move any window to any virtual desktop
  • Pin any window or application for them to show on all desktops
  • Notifications when switching, deleting, or renaming virtual desktops
  • Change the wallpaper for each desktop

Sample app

alternate text is missing from this package README image samples/VirtualDesktop.Showcase

Requirements

<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
  • .NET 6.0
  • .NET 7.0
  • .NET 8.0
  • 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, the target framework must be set to net6.0-windows10.0.19041.0 or later.

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

If it does not work, try creating an app.manifest file optimized 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()

Windows version support

Since this library is using undocumented interfaces, you need to reverse engineer your Windows version to support it.

The class IDs of undocumented interfaces tend to change between different OS versions. If the demo application crashes on start-up, you will need to provide the interfaces' IDs matching your Windows version.

Here are the interfaces we need:

  • IApplicationView
  • IApplicationViewCollection
  • IObjectArray
  • IServiceProvider
  • IVirtualDesktop
  • IVirtualDesktopManager
  • IVirtualDesktopManagerInternal
  • IVirtualDesktopNotification
  • IVirtualDesktopNotificationService
  • IVirtualDesktopPinnedApps

Once you have those IDs, add them in a new setting element in app.config. Make sure to specify the correct 9 digits Windows build and cumulative update version. You can get it using one of those methods:

  • From the UI run: winver
  • From shell run: ver
  • From powershell run: cmd /c ver

Don't forget to contribute back your changes.

Publish

To publish a new release specify your version in Directory.Build.props and push the changes with a commit description such as: Release vx.y.z where x, y, z form your version number. That should publish it on NuGet providing that your secret NUGET_API_KEY is still valid.

Internals

This library is essentially a C# wrapper for IVirtualDesktopManager and related undocumented interfaces. In order to support breaking binary changes between Windows versions we perform runtime compilation of a DLL providing access to the COM interfaces matching your OS build version.

Resources

License

This library is under the MIT License.

Credits

  • Thanks @Grabacr07 for creating this great piece of software
  • All contributors for sharing your work with the community
Product Compatible and additional computed target framework versions.
.NET net6.0-windows10.0.19041 is compatible.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0-windows was computed.  net8.0-windows10.0.19041 is compatible.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.9.2 136 4/28/2025
6.9.1 137 4/27/2025
6.9.0 139 4/27/2025
6.8.0 140 4/27/2025
6.7.0 115 4/27/2025
6.6.0 1,376 2/20/2024
6.5.0 138 2/4/2024
6.4.0 216 11/27/2023
6.3.0 150 11/21/2023
6.2.1 172 9/1/2023
6.2.0 152 9/1/2023
6.1.0 151 9/1/2023
6.0.0 163 8/31/2023
5.2.0 175 8/18/2023
5.1.2 168 8/16/2023
5.1.1 180 8/12/2023
5.1.0 169 8/12/2023
5.0.9 177 8/12/2023