![](/img/trans.png)
[英]How to get DispatcherQueue in WinUI 3 Desktop using Windows App SDK
[英]Keep WinUI 3 (Windows App SDK) window always at bottom
我有以下 window 使用 Windows 应用程序 SDK 1.1.5 和 WinUI 3,我想将它始终保持在底部,就在桌面的上方, m_AppWindow.MoveInZOrderAtBottom();
按照我的意图将它移动到最底部,但是一旦按下它就会回到前台。
单击后如何防止它进入前台? 我想它可能与 HWND 句柄有关。
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using System;
using WinRT.Interop;
namespace Widgets {
public sealed partial class MainWindow : Window {
private AppWindow m_AppWindow;
public MainWindow() {
this.InitializeComponent();
m_AppWindow = GetAppWindowForCurrentWindow();
m_AppWindow.MoveInZOrderAtBottom();
}
private AppWindow GetAppWindowForCurrentWindow() {
IntPtr hWnd = WindowNative.GetWindowHandle(this);
WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(wndId);
}
}
}
这只是来自 Visual Studio Blank App, Packaged (WinUI 3 in Desktop) C#
模板的稍微修改的MainWindow.cs
。
提前致谢。
你可以这样试试。
public sealed partial class MainWindow : Window
{
private AppWindow m_AppWindow;
public MainWindow()
{
this.InitializeComponent();
m_AppWindow = GetAppWindowForCurrentWindow();
m_AppWindow.Changed += M_AppWindow_Changed;
}
private void M_AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args)
{
if (args.DidZOrderChange is true)
{
m_AppWindow.MoveInZOrderAtBottom();
}
}
private AppWindow GetAppWindowForCurrentWindow()
{
IntPtr hWnd = WindowNative.GetWindowHandle(this);
WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(wndId);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.