[英]Setting a WinForms Form as Owner for a WPF Window
我有一個圍繞 System.Windows.Forms.Form 構建的主應用程序有一個舊的 System.Windows.Window 用戶可以調用它被設置為 Topmost。 我希望 Window 歸主應用程序所有,因此當應用程序最小化時它會最小化。 所以我預期的代碼是
TopmostDisplayWindow.Owner = MainAppForm;
但是,沒有采用 Form 的 Window.Owner 方法,並且 Window 沒有覆蓋采用所有者的 Show()。
有沒有一種簡單的方法可以為 MainAppForm 獲取一個窗口,還是需要更復雜的東西?
您可以使用WindowInteropHelper
並設置它的Owner
屬性:
var window = new YourWPFWindow();
WindowInteropHelper helper = new WindowInteropHelper(window);
helper.Owner = this.Handle;
window.Show();
在 Winform Form
主窗體中使用上面的代碼。 當您想要顯示 WPF 窗口時,請記住添加所需的引用: PresentationCode
、 PresentationFramework
、 WindowsBase
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.