Reputation: 2358
I have a WinForms application where I'm hosting a WPF user control in an ElementHost control. From that WPF UserControl I need to show a WPF dialog. While I could create the WPF Window and call ShowDialog(), I could get the dialog to "hide behind" the main app. How can I set the owner of the WPF dialog in this context?
EntryDialog entryDialog = new entryDialog();
bool? ret = entryDialog.ShowDialog();
if (ret.Value == true)
{
}
Upvotes: 2
Views: 1323
Reputation: 2358
The trick to getting the owner set was to access the underlying WinForms window and use the WPF WindowInteropHelper to pull it all together.
EntryDialog entryDialog = new entryDialog();
HwndSource source = (HwndSource)HwndSource.FromVisual(this);
new System.Windows.Interop.WindowInteropHelper(entryDialog).Owner = source.Handle;
bool? ret = entryDialog.ShowDialog();
if (ret.Value == true)
{
}
For the HwndSource you also need:
using System.Windows.Interop
This XAML reduces the task bar clutter
ShowInTaskbar="False"
Upvotes: 2