WPD ShowDialog and ElementHost

Is it possible to display a Modal window from a WPF user control that is a child of ElementHost and set the owner / parent of the modal window to the containing Form control?

I assume that you cannot do this, because the Owner property accepts an instance of Window, where I want to set it to the parent of the control element, which is the old element of the Windows Forms Form. Just wondering if there is a job or an alternative approach.

The problem is when the modal window is displayed and the user switches to another application, then back, the modal window is hidden and the user cannot interact with the main window. This is because Windows thinks that the modal window is still displayed when it is not, because there are no Owner / Parent relationships established.

Cheers, James.

+6
wpf showdialog elementhost
source share
3 answers

I am using WindowInteropHelper to solve this problem as follows:

var wpfDialog = new MyWpfDialog(); var interopHelper = new WindowInteropHelper(wpfDialog) { Owner = winFormsDialog.Handle }; wpfDialog.ShowDialog(); 
+8
source share

I know this post is old, but it occurred to me to find the winform window that contains the ElementHost from the wpf UserControl context, where you might not have access to the winform window. I found this to be useful, so I do not need to skip the host window.

 HwndSource winformWindow = (System.Windows.Interop.HwndSource.FromDependencyObject(wpfControlInElementHost) as System.Windows.Interop.HwndSource); if (winformWindow != null) { var interopHelper = new WindowInteropHelper(wpfWindow) { Owner = winformWindow.Handle }; } 
+4
source share
+2
source share

All Articles