How can I use Window.ShowActivated = false with Maximized window?

Posted by Anthony Brien on Stack Overflow See other posts from Stack Overflow or by Anthony Brien
Published on 2010-04-08T17:38:29Z Indexed on 2010/04/08 17:43 UTC
Read the original article Hit count: 786

Filed under:
|
|
|
|

I have an application that has a splash screen shown before I create my main window. I want to avoid the main window stealing the focus when it gets created if the user has focused another application while the splash screen was shown.

My application's startup looks like this:

private void Application_Startup(object sender, StartupEventArgs e)
{
    SplashScreenService.Start();

    // Initializing stuff...
    ...

    // Ready to open the main window.
    MainWindow mainWindow = MainWindow();
    mainWindow.ShowActivated = SplashScreenService.HasFocus();
    mainWindow.ShowDialog();
}

To prevent the main window from getting activated, I'm setting Window.ShowActivated to false, only if the splash screen has lost the focus. But this causes an exception:

InvalidOperationException: Cannot show Window when ShowActivated is false and WindowState is set to Maximized.

Indeed, my MainWindow sets the WindowState to Maximized (restored from previous session settings). I don't understand why there is such a limitation with the ShowActivated feature. I couldn't find any documentation about this issue.

I tried forcing WindowState to Normal when ShowActivated is false, and it prevents the exception, but it also activates the window! Maybe changing the window state actually causes an activation?

Is there a trick I can use to work around this? I want to restore my main window in a maximized state, and not have the main window steal focus away from other applications if the user has focused away from my app during the splash screen.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about focus