2
votes

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)
{
}
1

1 Answers

2
votes

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"