点击消息框中的StdinfoPage
按钮后,我想打开Go to Admin
页面
我怎样才能做到这一点?
这是我的按钮编码
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)
{
}
}
答案 0 :(得分:1)
根据此处的示例: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");
}