WPF c#按钮等待按钮按下

本文关键字:按钮 等待 WPF | 更新日期: 2023-09-27 18:08:02

我是编码新手

所以我要做的是button谁要等待
用户点击其中一个按钮继续

void Mainbutton()
{  
    //the program run throw so method  
    //Wait for the user to choose one  button (I made a numeric pad with buttons)  
    //Then use this information to work
}
我知道我的英语不是那么好谢谢大家

WPF c#按钮等待按钮按下

试试这样:

bool gotResponse = false;
//you need to run MainTask in a different thread
Thread thread = new Thread(new ThreadStart(DoWork));
thread.Start();
void DoWork()
{
     //do some work
     //when something else needed from user then popup message
     MessageBox.Show("say whatever you need to say");
     while(!gotResponse)
     {
          //note: this loop doesn't stop until gotResponse = true; 
     }
     //do rest of your work
}
private button_Click(object sender, RoutedEventArgs e)
{
     gotResponse = true;
}