[英]windows store app message dialog box
單擊消息框上的“ Go to Admin
按鈕后,我想打開StdinfoPage
頁面,我該怎么做? 這是我的按鈕編碼
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();
}
}
這是消息框代碼
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)
{
}
}
基於以下示例: http : //msdn.microsoft.com/library/windows/apps/windows.ui.popups.messagedialog.aspx ,您需要創建此方法,該方法將在“ Go to Admin
或“ Close
按鈕時執行被點擊
private void CommandInvokedHandler(IUICommand command)
{
// Check which button is clicked
if (command.Label == "Go to Admin")
{
// open StdinfoPage
this.Frame.Navigate(typeof(StdinfoPage));
}
}
並刪除this.Frame.Navigate(typeof(StdinfoPage));
內部if (privilege == 1)
塊
if (privilege == 1)
{
DisplayMsgBox("click to open the admin page ", "Go to Admin");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.