Custom Message Box

So just a quickie but for an improvement I’m making to Shoppers Calculator I decided one way to get past a hurdle I was up against was to use a MessageBox or similar to ask the user to enter some text, without taking them away from the current screen. Ah, but Messagebox just takes a caption, a message and allows OK and Cancel buttons – isn’t there a way to do a custom message box? Yes there is.

I came across this great article by Shawn Oster that described how to use CustomMessageBox via code or XAML and so I’m going to suggest you go there to take a look at it rather than me repro all the same information here.

One thing I will do though is mention something to consider if you are creating a message box in which the user will be be asked to enter text, you can save them a tap and make what is needed even more obvious by setting the focus to the text box you want them to edit.

However, the timing is crucial here – it doesn’t work to call it either before or after calling Show(), instead, bind to the Loaded event and add it there. It works beautifully:

TextBox myTextBox = new TextBox();
CustomMessageBox messageBox = new CustomMessageBox()
messageBox.Dismissed += (s1, e1) =>
   //handle result}

Having done this, you will find that the moment the message box opens, so does the keypad – no big deal, but you have just saved the user the faff of tapping in the textbox which they had to do anyway, and helping the user helps the user think your app is great.

Anyway, enough for now, go and read Shawn’s post for a more detailed look at CustomMessageBox.

About bluechrism

I am a software developer with most professional experience in the Windows .Net realm and I'm currently a WPF developer with Starkey Labs. However, I have wanted for some time to start the mobile developer journey properly and being an N900 owner, this was to be in the realm of QT. Job hunting, moving to Minnesota and changing jobs put my plans on hold 6-12 months but things are starting to settle now, just as I'm getting sorted to start some things, Microsoft and Nokia merge. This blog is about my novice mobile development experiences and hopefully will end up complete with links to download some apps on various platforms, but obviously by the name, Sybian, Maemo/Meego and Windows Mobile. In other stuff, I am English, I support Everton FC, I have visited Glastonbury music festival 5 times and recommend it to anyone. I am married and my wife and i have a dog called Friday.
This entry was posted in Development, Windows Phone and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s