VirtualDesktop is C# wrapper for IVirtualDesktopManager on Windows 11 (and Windows 10).
samples/VirtualDesktop.Showcase
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
Install NuGet package(s).
PM> Install-Package VirtualDesktop
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> <!-- Windows 10 / 11--> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> </application> </compatibility>
The namespace to use is WindowsDesktop
.
// 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();
// 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();
// 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()
This library is under the MIT License.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4