如何在winui3

问题描述 投票:0回答:0
对话框应显示在父窗口的前面。

当父窗口关闭时,对话框应关闭。

    我尝试过的代码。我使用了setparent,但是对话框嵌入了主窗口中,对话框的appwindow变为null。
  • public sealed partial class ModelessDialog : Window { public ModelessDialog(SizeInt32 windowSize, Window _parent) { this.InitializeComponent(); OverlappedPresenter presenter = (OverlappedPresenter)this.AppWindow.Presenter; presenter.IsResizable = true; this.AppWindow.SetPresenter(presenter); this.AppWindow.IsShownInSwitchers = false; this.AppWindow.Resize(windowSize); IntPtr windowHandle = App.GetWindowHandle(this); IntPtr parentHandle = App.GetWindowHandle(_parent); SetParent(windowHandle, parentHandle); } public IntPtr GetWindowHandle(in Window _window) { return WinRT.Interop.WindowNative.GetWindowHandle(_window); } [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); }
  • 您可以使用父母的
claped事件来关闭“无调”窗口。

public partial class ModelessWindow : Window { public ModelessWindow(SizeInt32 size, Window parent) : base() { parent.Closed += (s, e) => this.Close(); this.AppWindow.MoveAndResize( new RectInt32( parent.AppWindow.Position.X, parent.AppWindow.Position.Y, size.Width, size.Height)); } }

	
c# winui-3 winui windows-app-sdk
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.