我正在使用Modern UI并尝试创建一个提示问题的对话框,然后等待响应。我可以使用messagebox执行此操作,但我会尝试使用现代UI。我不确定如何获得按钮点击值。
if (testapp.linkvalue != "NULL")
{
var v = new ModernDialog
{
Title = "my test",
Content = "pewpew lazers rule. If you agree click ok"
};
v.Buttons = new Button[] { v.OkButton, v.CancelButton };
var r = v.ShowDialog();
if (????????????????)
{
MessageBox.Show("ok was clicked");
}
else
{
MessageBox.Show("cancel was clicked");
}
}
答案 0 :(得分:5)
if (testapp.linkvalue != "NULL")
{
var v = new ModernDialog
{
Title = "my test",
Content = "pewpew lazers rule. If you agree click ok"
};
v.OkButton.Click += new RoutedEventHandler(OkButton_Click);
v.Buttons = new Button[] { v.OkButton, v.CancelButton };
var r = v.ShowDialog();
}
//And Then Create OkButtonClick
private void OkButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("ok was clicked");
}
答案 1 :(得分:2)
这可能是使用扩展方法的另一种解决方案。
var r = v.ShowDialogOKCancel();
if (r==MessageBoxResult.OK)
{
MessageBox.Show("ok was clicked");
}
else
{
MessageBox.Show("cancel was clicked");
}
static class ModernDialogExtension
{
static MessageBoxResult result;
public static MessageBoxResult ShowDialogOKCancel(this FirstFloor.ModernUI.Windows.Controls.ModernDialog modernDialog)
{
result = MessageBoxResult.Cancel;
modernDialog.OkButton.Click += new RoutedEventHandler(OkButton_Click);
modernDialog.Buttons = new Button[] { modernDialog.OkButton, modernDialog.CloseButton };
modernDialog.ShowDialog();
return result;
}
private static void OkButton_Click(object sender, RoutedEventArgs e)
{
result = MessageBoxResult.OK;
}
}
答案 2 :(得分:2)
private void CommonDialog_Click(object sender, RoutedEventArgs e)
{
var dlg = new ModernDialog {
Title = "Common dialog",
Content = new LoremIpsum()
};
dlg.Buttons = new Button[] { dlg.OkButton, dlg.CancelButton};
dlg.ShowDialog();
this.dialogResult.Text = dlg.DialogResult.HasValue ? dlg.DialogResult.ToString() : "<null>";
this.dialogMessageBoxResult.Text = dlg.MessageBoxResult.ToString();
}