15

I'm new to WPF so this is probably a pretty easy problem. I open a dialog window using ShowDialog(). Then, if I click into another window that's fullscreen or just covers my dialog, it's difficult to get back to the dialog. The icon that shows up in the taskbar takes me back to the main WPF window but the dialog stays hidden behind the other window. I either have to minimize the blocking window or Alt-Tab back into my application (which will show the dialog but leave the main window hidden).

The definition for the window looks like:

<Window x:Class="MyProject.MyWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        ResizeMode="CanResizeWithGrip"
        ShowInTaskbar="False"
        WindowStartupLocation="CenterOwner"
        Width="750"
        Height="565"
        Title="MyWindow">

I'm opening it like:

var dlg = new MyWindow();
if (dlg.ShowDialog() != true)
    return;
Jason
  • 1,766
  • 2
  • 14
  • 24

1 Answers1

18

You should set the owner of your dialog window. Something like this.

var dlg = new MyWindow();
dlg.Owner = this;
if (dlg.ShowDialog() != true)    
    return;
Samuel Jack
  • 32,712
  • 16
  • 118
  • 155
Yiğit Yener
  • 5,796
  • 1
  • 23
  • 26
  • Is there any way that's more automated? Passing it as a parameter could be one, but there might be a better one? – bytecode77 Jul 01 '16 at 09:37