Slions.VirtualDesktop.WinForms
6.8.0
Prefix Reserved
See the version list below for details.
dotnet add package Slions.VirtualDesktop.WinForms --version 6.8.0
NuGet\Install-Package Slions.VirtualDesktop.WinForms -Version 6.8.0
<PackageReference Include="Slions.VirtualDesktop.WinForms" Version="6.8.0" />
<PackageVersion Include="Slions.VirtualDesktop.WinForms" Version="6.8.0" />
<PackageReference Include="Slions.VirtualDesktop.WinForms" />
paket add Slions.VirtualDesktop.WinForms --version 6.8.0
#r "nuget: Slions.VirtualDesktop.WinForms, 6.8.0"
#addin nuget:?package=Slions.VirtualDesktop.WinForms&version=6.8.0
#tool nuget:?package=Slions.VirtualDesktop.WinForms&version=6.8.0
VirtualDesktop
.NET library enabling Windows multiple desktop operations
Platform | NuGet | Downloads |
---|---|---|
Core | ||
Forms | ||
WPF |
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>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
- VirtualDesktop - Core classes for VirtualDesktop.
- VirtualDesktop.WPF - Provides extension methods for WPF Window class.
- VirtualDesktop.WinForms - Provides extension methods for Form class.
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()
Windows version support
Since this library is using undocumented interfaces you need to properly reverse engineer your Windows version to support it.
The class IDs of some of the undocumented interfaces we use tend to change a lot between different versions of Windows. If the demo application crashes on start-up chances are all you need to do is provide the proper IDs for the version of Windows you are running on.
Here are the interfaces we need:
IApplicationView
IApplicationViewCollection
IObjectArray
IServiceProvider
IVirtualDesktop
IVirtualDesktopManager
IVirtualDesktopManagerInternal
IVirtualDesktopNotification
IVirtualDesktopNotificationService
IVirtualDesktopPinnedApps
Once you have the IDs add them in a new setting
element in app.config.
Make sure to specify the correct 5 digits Windows build 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
Make sure 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
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
- samples/README.md
- StackOverflow
- Upstream repository - unmaintained
- VirtualDesktop command line tool - not using this library
- VirtualDesktop AutoHotKey DLL
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 | Versions 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. net10.0-windows was computed. |
-
net6.0-windows10.0.19041
- Slions.VirtualDesktop (>= 6.8.0)
-
net7.0-windows10.0.19041
- Slions.VirtualDesktop (>= 6.8.0)
-
net8.0-windows10.0.19041
- Slions.VirtualDesktop (>= 6.8.0)
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 | 266 | 4/28/2025 |
6.9.1 | 147 | 4/27/2025 |
6.9.0 | 149 | 4/27/2025 |
6.8.0 | 150 | 4/27/2025 |
6.7.0 | 126 | 4/27/2025 |
6.6.0 | 1,398 | 2/20/2024 |
6.5.0 | 145 | 2/4/2024 |
6.4.0 | 219 | 11/27/2023 |
6.3.0 | 153 | 11/21/2023 |
6.2.1 | 178 | 9/1/2023 |
6.2.0 | 158 | 9/1/2023 |
6.1.0 | 156 | 9/1/2023 |
6.0.0 | 169 | 8/31/2023 |
5.2.0 | 181 | 8/18/2023 |
5.1.2 | 174 | 8/16/2023 |
5.1.1 | 186 | 8/12/2023 |
5.1.0 | 175 | 8/12/2023 |
5.0.9 | 183 | 8/12/2023 |