我有一个构建在System.Windows.Forms.Form上的主应用程序,有一个遗留的System.Windows.Window,用户可以调用它,它被设置为最顶层。我希望主应用程序拥有这个窗口,所以当应用程序最小化时,它就会最小化。所以我期望的代码是
TopmostDisplayWindow.Owner = MainAppForm;
但是,没有采用表单的Window.Owner方法,而且窗口没有覆盖作为所有者的Show()。
有什么简单的方法可以为MainAppForm找到一个窗口,还是需要一些更复杂的东西呢?
发布于 2015-09-21 10:39:48
您可以使用WindowInteropHelper
并设置它的Owner
属性:
var window = new YourWPFWindow();
WindowInteropHelper helper = new WindowInteropHelper(window);
helper.Owner = this.Handle;
window.Show();
在主/父窗体(即Winform Form
)中使用上面的代码。当要显示WPF窗口时,请记住添加以下引用:
PresentationCore
PresentationFramework
WindowsBase
https://stackoverflow.com/questions/32701680
复制