Guide.BeginShowMessageBox wrapper

Posted by Daniel Moth on Daniel Moth See other posts from Daniel Moth or by Daniel Moth
Published on Thu, 30 Dec 2010 08:38:17 GMT Indexed on 2010/12/30 9:01 UTC
Read the original article Hit count: 348

Filed under:

imageWhile coding for Windows Phone 7 using Silverlight, I was really disappointed with the built-in MessageBox class, so I found an alternative. My disappointment was the fact that:

  1. Display of the messagebox causes the phone to vibrate (!)
  2. Display of the messagebox causes the phone to make an annoying sound.
  3. You can only have "ok" and "cancel" buttons (no other button captions).

I was using the messagebox something like this:

      // Produces unwanted sound and vibration. 
      // ...plus no customization of button captions.
      if (MessageBox.Show("my message", "my caption", MessageBoxButton.OKCancel)
              == MessageBoxResult.OK)
      {
        // Do something
        Debug.WriteLine("OK");
      }

…and wanted to make minimal changes throughout my code to change it to this:

      // no sound or vibration
      // ...plus bonus of customizing button captions
      if (MyMessageBox.Show("my message", "my caption", "ok, got it", "that sucks")
              == MyMessageBoxResult.Button1)
      {
        // Do something
        Debug.WriteLine("OK");
      }

It turns out there is a much more powerful class in the XNA framework that delivered on my requirements (and offers even more features that I didn't need like choice of sounds and not blocking the caller): Guide.BeginShowMessageBox. You can use it simply by adding an assembly reference to Microsoft.Xna.Framework.GamerServices.

I wrote a little wrapper for my needs and you can find it here (ready to enhance with your needs): MyMessageBox.cs.txt.




Comments about this post welcome at the original blog.

© Daniel Moth or respective owner

Related posts about MobileAndEmbedded

  • Translator by Moth v2

    as seen on Daniel Moth - Search for 'Daniel Moth'
    If you are looking for the full manual for this Windows Phone app you can find it here: "Translator by Moth". While the manual has no images (just text), in this post I will share images and if you like them, go get "Translator by Moth" from the Windows Phone marketplace. open the app from… >>> More

  • Windows Phone 7 developer resources

    as seen on Daniel Moth - Search for 'Daniel Moth'
    Developers of Windows Mobile 6.x (and indeed Windows CE) applications still use the rich .NET Compact Framework 3.5 with Visual Studio 2008 for development. That is still a great platform and the Mobile Development Handbook is still a useful resource (if I may say so myself :-). The release of Windows… >>> More

  • ScrollViewer.EnsureVisible for Windows Phone

    as seen on Daniel Moth - Search for 'Daniel Moth'
    In my Translator By Moth app, on both the current and saved pivot pages the need arose to programmatically scroll to the bottom. In the former, case it is when a translation takes place (if the text is too long, I want to scroll to the bottom of the translation so the user can focus on that, and not… >>> More

  • "Translator by Moth"

    as seen on Daniel Moth - Search for 'Daniel Moth'
    This article serves as the manual for the free Windows Phone 7 app called "Translator by Moth". The app is available from the following link (browse the link on your Window Phone 7 phone, or from your PC with zune software installed): http://social.zune.net/redirect?type=phoneApp&id=bcd09f8e-8211-e011-9264-00237de2db9e… >>> More

  • Watermark TextBox for Windows Phone

    as seen on Daniel Moth - Search for 'Daniel Moth'
    In my Translator by Moth app, in the textbox where the user enters a translation I show a "prompt" for the user that goes away when they tap on it to enter text (and returns if the textbox remains/becomes empty). See screenshot on the right (or download the free app to experience it). Back… >>> More