Jeb*_*Jeb 5 .net c# windows wpf winforms
我想知道是否有人可以帮助我解决这个相当令人困惑的情况。我有一个WPF表单myForm,该表单在WinForm应用程序中以模态显示(不使用ElementHost)。如果我使用默认的WindowStyle,并且一切显示在任务栏中,则一切正常。但是,现在我不希望该表单显示在任务栏中或包含最小化按钮,因此我执行了以下操作:
MyForm myForm = new MyForm();
myForm.ShowInTaskbar = false;
myForm.WindowStyle = System.Windows.WindowStyle.ToolWindow;
myForm.WindowStartupLocation =System.Windows.WindowStartupLocation.CenterOwner;
myForm.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
现在,wpf窗体将按预期方式显示,并且没有最小化按钮。如果我现在在任务栏中选择“父” winform应用程序,则wpf表单将消失,并且似乎没有任何返回它的方法!我读这是相似但不相同的(纯WPF应用程序),所以我能理解为什么主要的应用程序不会在ALT + TAB菜单出现,但谁能告诉我怎么能回到WPF形式?
提前致谢。
使用,WindowsInteropHelper您可以使用Winforms表单包装托管的WPF表单并将其父对象设置为Winforms控件,从而防止WPF表单消失(也正如dowhilefor和Hans Passant指出的那样)
例如:
// Use the interop helper for the specified wpf window hosted by the win32 owner
WindowInteropHelper wih = new WindowInteropHelper(wpfForm);
wih.Owner = this.someWin32FormsControl.Handle;
Run Code Online (Sandbox Code Playgroud)