Infovark Underground

  • news
    • infoblog
    • underground
  • product
  • download
  • buy
  • support
  • about
    • ← Highlighting query terms in a WPF TextBlock
    • Review: Brownfield Application Development in .NET →

    Using Modal Dialogs with a Splash Screen in WPF

    23 Mar 2011 by Dean in .NET, Programming, WPF / No Comments

    We ran into a strange problem while our Infovark application was starting up. If we displayed a modal dialog prior to our main window, it would appear briefly on the screen, then vanish. The user wouldn’t have any time to click any buttons, much less actually read the message on the dialog.

    We’d been using modal dialogs in our startup routine for several purposes. We’d display an error message if certain application prerequisites hadn’t been met. We might inform the user that the system was performing an upgrade. Or, most important, we might show our trial/evaluation dialog. This last message tells the user how many days were remaining in the evaluation period, and provides a way for the user to visit our website and buy a copy. (Critical functionality for us!)

    All of these messages had been working properly in our integration tests. And then one day they stopped working.

    Splish splash

    After looking through our check-in logs and hunting around online, we discovered that the problem had to do with the WPF Splash Screen mechanism. We’d followed the instructions in How To Add a Splash Screen to a WPF Application and added a static image to our project to display to the user while the application was loading.

    But apparently, this has a nasty side effect of clobbering any modal dialogs that you show before your first non-modal window. A few other folks have noted the same problem. It’s been submitted twice on Microsoft Connect as a bug:

    • WPF splash screen closes MessageBox
    • WPF splash screen dismisses dialog box

    But it’s not clear whether Microsoft’s going to address the issue. The cause of the problem is that a modal dialog without an explicit parent window set will automatically attach itself to an active non-modal window. It’s a nifty behavior in most cases, but if a modal dialog attaches itself to a splash screen, and the splash screen is dismissed — well, so is your dialog!

    All washed up

    So, what are our options? One is to avoid Visual Studio’s built-in splash screen feature entirely and create our own splash screen. This thread in the MSDN forums describes how that can be done.

    That seemed like too much work for us, which left us with three possible workarounds:

    1. Use a hidden window. Create a tiny, non-modal window to act as a parent for your MessageBox or modal dialog.
    2. Create non-modal message windows. Change your startup mode to explicit shutdown and use a non-modal window to display your message.
    3. Call MessageBox twice. Apparently, the problem only affects the first modal dialog shown. So you could simply call your modal dialog twice, if you didn’t mind the flash of the first one opening and closing.

    I don’t recommend that last technique — though it does work — so I’m not going to provide a link to it.

    Drying off

    I found several custom implementations of splash screens on CodePlex, but at this stage, so close to our 2.0 release, I didn’t want to add any code to our project that I didn’t thoroughly understand.

    Since our software licensing code come from a third party, we couldn’t easily modify all of the windows shown during start-up to be non-modal.

    So ultimately we decided to use the hidden window workaround. It seemed the quickest way to get the behavior we wanted. It feels a bit dirty, but I can’t justify rolling my own splash screen implementation just to display a static “Loading…” image.

    I’d really like to see Microsoft fix this one. If you think so too, vote for the issue here. Thanks!

    No related posts.

    • Tweet
    • Tags:
    • modal dialog
    • splash screen

    Leave a Comment

    Posting your comment...

    Subscribe to these comments via email

    • Categories

      • .NET (41)
      • AJAX (3)
      • Books (7)
      • HTML (9)
      • Infovark (8)
      • Programming (48)
      • REST (11)
      • SQL (3)
      • Testing (3)
      • Tools (13)
      • UI (3)
      • WCF (11)
      • Web Services (8)
      • WPF (4)
      • XML (4)
    • Archives

    • Get future articles


       

    • Blogroll

      • Ajaxian
      • Anne Van Kesteren
      • Brain.Save()
      • Coding Horror
      • Eric Sink
      • Joel Spolsky
      • John Resig
      • Mark Pilgrim
      • Raymond Chen
      • Scott Hansleman
      • Secret Geek
      • Steve Yegge
      • The Daily WTF
      • The Database Programmer
    • Meta

      • Log in
      • Entries RSS
      • Comments RSS
      • WordPress.org
  • Site map

    • News
    • Product
    • Download
    • Buy
    • Support
    • About
  • Recent Posts

    • Review: Brownfield Application Development in .NET
    • Using Modal Dialogs with a Splash Screen in WPF
    • Highlighting query terms in a WPF TextBlock
    • Getting XAML Hyperlink text to wrap
    • How to format the XAML Hyperlink NavigateUri
  • Twitter

    Copyright 2011 Infovark, Inc. All rights reserved.