Modal dialog focus problems on WPF application

Posted by Donal on Stack Overflow See other posts from Stack Overflow or by Donal
Published on 2010-06-17T13:39:37Z Indexed on 2010/06/17 13:43 UTC
Read the original article Hit count: 297

Filed under:
|
|
|

Hi,

I have a problem with my wpf application where a modal dialog will appear behind the main application causing it to hang.

It is very inconsistent, where most of the time the pop-up works correctly and is shown in front but occasionally it will pop-up behind, which stops any interaction with it. I can still close the dialog using the taskbar if this happens. I have noticed that it generally occurs when lots of other applications are open and the taskbar is full. Also, I am working with two screens and the problem only occurs on the screen with the taskbar - very wierd!

The dialog is a window control, which contains an injected usercontrol as it's data context. To set the owner of the window before calling ShowDialog(), the first active window in the application is used instead of Window.GetWindow(this):


private static Window GetOwner()
{
    if (Application.Current != null)
    {
      var owner = Application.Current.Windows.Cast().FirstOrDefault(w => w.IsActive);
      return owner ?? Application.Current.MainWindow;
    }
    return null;
}

Any ideas of what may be causing this problem? or even how to try and track it so I can gather more information when it happens?

Thanks, Donal

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf