简体   繁体   English

跨多个窗口的永久窗口10个虚拟桌面?

[英]Persistent window across multiple windows 10 virtual desktops?

I have C# WPF program with multiple windows. 我有多个窗口的C#WPF程序。 I've added support for windows 10 desktops, but the users would like some windows to stay on the screen when moving between desktops. 我已经添加了对Windows 10桌面的支持,但用户希望在桌面之间移动时有些窗口留在屏幕上。

For example if window A is opened on the first desktop and they flip to the second desktop they want window A to stay in the same location on the new desktop. 例如,如果在第一个桌面上打开了窗口A并且它们翻转到第二个桌面,则他们希望窗口A保持在新桌面上的相同位置。

The only functions I'm aware of are from the VirtualDesktopManager: 我所知道的唯一功能来自VirtualDesktopManager:

GetWindowsDesktopId()
IsWindowOnCurrentVirtualDesktop()
MoveWindowToDesktop()

Is there a way to do this? 有没有办法做到这一点?

Also is there a way to detect when a desktop flip has been initiated? 还有一种方法可以检测桌面翻转何时启动? Because if so I could always call IsWindowOnCurrentVirtualDesktop() and if the answer is no I could call MoveWindowToDesktop() to place it there. 因为如果是这样我总是可以调用IsWindowOnCurrentVirtualDesktop(),如果答案是否定的,我可以调用MoveWindowToDesktop()将它放在那里。 Seems like a bit of a hack, but would get the job done if i had a way to detect the desktop change. 看起来像是一个黑客,但如果我有办法检测桌面更改,将完成工作。

You can detect the virtual desktop change, found a nice GitHub project with the necessary code as well as more functions that deal with Virtual Desktops in Windows 10. 您可以检测虚拟桌面更改,找到一个很好的GitHub项目,其中包含必要的代码以及更多处理Windows 10中虚拟桌面的功能。

Virtual Desktop GitHub 虚拟桌面GitHub

To get the event and simulate the window staying on every desktop you can do the following. 要获取事件并模拟停留在每个桌面上的窗口,您可以执行以下操作。

VirtualDesktop.CurrentChanged += (o, e) =>
{
    this.Dispatcher.Invoke(() =>
    {
        var h = new WindowInteropHelper(this).Handle;

        if (!VirtualDesktopHelper.IsCurrentVirtualDesktop(h))
        {
            this.MoveToDesktop(VirtualDesktop.Current);
        }
    });
};

The Dispatcher.Invoke is necessary because the event is on a different thread then the UI one, so the call must be marshaled to the UI thread. Dispatcher.Invoke是必需的,因为事件位于与UI不同的线程上,因此必须将调用封送到UI线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM