[英]Keep WinUI 3 (Windows App SDK) window always at bottom
I have the following window using Windows App SDK 1.1.5 and WinUI 3, I want to keep it always at the bottom, just above the desktop, m_AppWindow.MoveInZOrderAtBottom();
我有以下 window 使用 Windows 应用程序 SDK 1.1.5 和 WinUI 3,我想将它始终保持在底部,就在桌面的上方,
m_AppWindow.MoveInZOrderAtBottom();
moves it to the very bottom as I intended, but once it is pressed it comes back to the foreground.按照我的意图将它移动到最底部,但是一旦按下它就会回到前台。
How can I prevent it from coming to the foreground once clicked?单击后如何防止它进入前台? I suppose it may be related to the HWND handle.
我想它可能与 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);
}
}
}
This is just a slightly modified MainWindow.cs
from the visual studio Blank App, Packaged (WinUI 3 in Desktop) C#
template.这只是来自 Visual Studio
Blank App, Packaged (WinUI 3 in Desktop) C#
模板的稍微修改的MainWindow.cs
。
Thanks in advance.提前致谢。
You can try it this way.你可以这样试试。
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.