IT tutorials
 
Mobile
 

Windows Phone 8 : Windows Phone Toolkit (part 5) - CustomMessageBox

6/23/2013 7:55:46 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

10. CustomMessageBox

Inside the toolkit is a special type of control for getting feedback from the user. Although there is a built-in MessageBox class, it is simple and doesn’t allow you to customize the experience. Unsurprisingly, the CustomMessageBox class from the Toolkit attempts to remedy this.

To use the CustomMessageBox, you simply create an instance of the class and set certain properties. At a minimum you should set the Caption, Message, and Button content properties, like so:

var myMessage = new CustomMessageBox()
{
  Caption = "A Custom MessageBox",
  Message = "This is a custom MessageBox example.",
  LeftButtonContent = "cancel",
  RightButtonContent = "ok",
};

myMessage.Show();

Running this code results in a message box at the top of the screen, as shown in Figure 17.

Image

FIGURE 17 Simple CustomMessageBox

The underlying page is obscured with a semitransparent overlay. The Caption property is shown in larger text at the top of the message box, and the Message is shown in smaller text. The Caption should be the title of the message box, and the Message is used to hold a longer set of text to convey the information to the user.

In addition to the simple Caption and Message, you can also specify the Content of the message box to show specialized controls as necessary. For example, you could have a HyperlinkButton that enables the user to navigate to a specified page:

var link = new HyperlinkButton()
{
  Content = "About...",
  NavigateUri = new Uri("http://wp7book.com")
};

var myMessage = new CustomMessageBox()
{
  Caption = "A Custom MessageBox",
  Message = "This is a custom MessageBox example.",
  LeftButtonContent = "cancel",
  RightButtonContent = "ok",
  Content = link,
};

myMessage.Show();

In this case, creating a complex control (for example, HyperlinkButton) and then assigning it to the Content of the control places it after the Message, as shown in Figure 18.

Image

FIGURE 18 Using Content in the CustomMessageBox

You can also specify that the CustomMessageBox is a full-screen message box by specifying the IsFullScreen property. You can see this same message box with the IsFullScreen flag enabled in Figure 19.

Image

FIGURE 19 The CustomMessageBox in Full Screen Mode

The CustomMessageBox class has the concept of a left and right button. When the user selects either of these, the message box is closed. The user can also press the back button to close the message box without selecting a button. You will want to be able to know which button (if any) was pressed. To deal with this, you’ll need to handle the Dismissed event as shown:

var myMessage = new CustomMessageBox()
{
  Caption = "A Custom MessageBox",
  Message = "This is a custom MessageBox example.",
  LeftButtonContent = "cancel",
  RightButtonContent = "ok",
};

myMessage.Dismissed += myMessage_Dismissed;

myMessage.Show();

The event handler will be passed however the user actually dismissed the message box. You can test this by checking the event arguments of the event:

void myMessage_Dismissed(object sender, DismissedEventArgs e)
{
  switch (e.Result)
  {
    case CustomMessageBoxResult.RightButton:
      results.Text = "Right";
      break;
    case CustomMessageBoxResult.LeftButton:
      results.Text = "Left";
      break;
    case CustomMessageBoxResult.None:
    default: // Back button or escape
      results.Text = "None";
      break;
  }
}

The DismissedEventArgs contains a property called Result that contains the type of dismissal the message box handled. As the code here shows, you can see whether the left or right button was pressed. If neither was pressed, the result will contain the CustomMessageBoxResult.None as the value. In this way, you can handle the dismissal correctly.

 
Others
 
- Windows Phone 8 : Windows Phone Toolkit (part 4) - ToggleSwitch Control, ExpanderView Control, PhoneTextBox Control
- Windows Phone 8 : Windows Phone Toolkit (part 3) - ListPicker Control, LongListSelector Control
- Windows Phone 8 : Windows Phone Toolkit (part 2) - ContextMenu Control, DatePicker and TimePicker Controls
- Windows Phone 8 : Windows Phone Toolkit (part 1) - AutoCompleteBox Control
- Android 3 : Employing Basic Widgets - Turn the Radio Up, It's Quite a View
- Android 3 : Employing Basic Widgets - Just Another Box to Check
- iTunes on Your iPad : Purchasing or Renting Music, Videos, Podcasts, and More
- iTunes on Your iPad : iTunes U – Great Educational Content, Searching iTunes
- iTunes on Your iPad : Finding Music with Featured, Top Charts, and Genius
- BlackBerry Java Application Development - Changing the perspective
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us