Search code examples
c#asynchronouspopupwindows-store-appsmessagebox

windows store app message dialog box


I want to open the StdinfoPage page after clicking the Go to Admin button on the message box how can i do that? here is my button coding

private void button_login_Click(object sender, RoutedEventArgs e)
    {            
        if (MyReader.HasRows && this.Frame != null)
        {
            while (MyReader.Read())
            {
                if (privilege == 1)
                {
                    DisplayMsgBox("click  to open the admin page ", "Go to Admin");
                    this.Frame.Navigate(typeof(StdinfoPage));
                }                                    
                else
                {
                    DisplayMsgBox("privilege 0", "ok");
                }   
            }
        }                
        else
        {
            DisplayMsgBox("sucess else", "ok");
        }

        conn.Close();
    }

}

here is message box code

  private async void DisplayMsgBox(string displayMsg, string displayBtn)
    {
        try
        {
            // Create the message dialog and set its content
        var messageDialog = new MessageDialog(displayMsg);
        // Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers           
        messageDialog.Commands.Add(new UICommand(displayBtn, new UICommandInvokedHandler(this.CommandInvokedHandler)));
        messageDialog.Commands.Add(new UICommand("Close", new UICommandInvokedHandler(this.CommandInvokedHandler)));
        // Set the command that will be invoked by default
        messageDialog.DefaultCommandIndex = 0;
        // Set the command to be invoked when escape is pressed
        messageDialog.CancelCommandIndex = 1;
        // Show the message dialog
        await messageDialog.ShowAsync();            
        }
        catch (Exception)
        {  
        }
    }

Solution

  • Based on the example from here: http://msdn.microsoft.com/library/windows/apps/windows.ui.popups.messagedialog.aspx, you need to create this method that will be executed when Go to Admin or Close button is clicked

    private void CommandInvokedHandler(IUICommand command)
    {
        // Check which button is clicked
        if (command.Label == "Go to Admin")
        {
            // open StdinfoPage
            this.Frame.Navigate(typeof(StdinfoPage));
        }
    }
    

    and delete this.Frame.Navigate(typeof(StdinfoPage)); inside if (privilege == 1) block

    if (privilege == 1)
    {
        DisplayMsgBox("click  to open the admin page ", "Go to Admin");
    }