Custom commands in Windows store Message Dialogs

Message Dialogs are important part of windows store app and they help us providing popup messages and quick information in required places. Typically a message dialog covers the entire screen and by default has a close button. Windows store apps allow us to change these default characteristics of a message dialog.

The default close button in message dialog for windows store app can be removed and new buttons with custom click event handlers can be added to it. These events can be then later used to catch user interactions with the information.

Below is a code piece along with XAML to explain it all:

XAML code

<TextBlockx:="tbMessageInputs" Height="500" FontSize="20" Width="500" HorizontalAlignment="Center" VerticalAlignment="Center"></>

CSharp Code for the XAML

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected OnNavigatedTo(e)
            //create message dialog
            MessageDialog msgDialog = ("Custom Buttons and Events dialog");

            //remove all the commands

            //create new commands with custon click events on them
            UICommand commandOk = ("I am Ok with it", OkClicked);

            UICommand commandDisAgree = ("I Disagree", DisAgreeClicked);

            //add the commands to the message dialog

            //display the message dialog
            await msgDialog.ShowAsync();

        /// <summary>
        /// Executed when disagree button clicked
        /// populate the text box for results
        /// </summary>
        /// <param name="command"></param>
        private DisAgreeClicked(command)
            tbMessageInputs.Text = "DisAgree Clicked";

        /// <summary>
        /// executed when ok button is clicked
        /// and text box is populated
        /// </summary>
        /// <param name="command"></param>
        private OkClicked(command)
            tbMessageInputs.Text = "Ok Clicked";

In a message dialog more than two commands can be appended. Based on these commands we can intercept the user interactions and process the desired code or operation.

Written By: Anobik Dey, Software Developer, Mindfire Solutions

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