我使用C#语言。 我想创建一个方法,它将执行一些操作并等待用户单击其中四个按钮之一。我希望类似于MessageDialog异步方法,等待用户单击“是”或“否”:
private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var x = new MessageDialog("Yes or no?", "Choose");
x.Commands.Add(new UICommand("Yes", (UICommandInvokeHandler) =>
{
// blabla
}));
x.Commands.Add(new UICommand("No", (UICommandInvokeHandler) =>
{
// blabla
}));
await x.ShowAsync();
}
问题在于我无法使用这种方法(MessageDialog),因为我想要4个选项,但MessageDialog最多只能提供3个选项。
编辑:
private void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// doing some stuff
Method();
// doing some other stuff
}
private void Method()
{
// makes everything in UI invisible
// then makes the four buttons that were previously invisible, //visible
// here I want the program to stop and wait the user to press one of //the four buttons
// and then make the UI visible and the 4 buttons invisibl
}
EventHandler
,它们会“折叠”所有的按钮,并且知道哪个按钮被点击,因为它在object sender
内部。 - i3arnonprivate void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { //做一些事情 Method(); //做一些其他的事情 }
private void Method() { //使UI中的所有内容都不可见 //然后使之前不可见的四个按钮变为可见 //在这里,我希望程序停下来等待用户按下其中一个四个按钮 //然后使UI可见,四个按钮不可见 } - user2975038Method
更改UI后,它应该结束,Button_Click
之后不应有其他内容。您应该有一个不同的Button_Click2
方法,在单击4个按钮时运行,并且它所做的是“//做一些其他事情”。这将完全按照您描述的方式进行,并且非常简单。 - i3arnon