如何编程等待自定义消息框确定,取消,是,无响应?由于我的自然语言,我一直在使用自定义消息框,因为消息框只有英语,是的,没有,我找到了这个:在 Windows Phone 7 上自定义消息框
private MessageBoxService CustomMsgBox= new MessageBoxService();
public async void Handle(RecordRequest message)
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
Dispatcher.BeginInvoke(() =>
{
CustomMsgBox.Closed += CustomMsgBox_Closed;
CustomMsgBox.Closed += (s, e) => waitHandle.Set();
CustomMsgBox.Show(
"Login Please! ",
"Kayıt",
MessageBoxServiceButton.OKCancel);
});
waitHandle.WaitOne();
// Must Wait MessageBox Ok or Cancel like Normal MessageBox!!!
Login.IsOpen= true;
// do something ...
}
void CustomMsgBox_Closed(object sender, EventArgs e)
{
this.CustomMsgBox.Closed -= this.CustomMsgBox_Closed;
string rst = this.CustomMsgBox.Result.ToString();
}
通常 wp8 消息框在单击 OK-Cancel 时被锁定。但我的 Costom MessageBox 并没有等待。如何锁定我的 CustomMsgBox,直到单击确定-取消。
示例用法:
private PixelLab.Common.MessageBoxService _service = new PixelLab.Common.MessageBoxService();
private void Button_Click(object sender, RoutedEventArgs e)
{
this._service.Closed += this.MessageBoxService_Closed;
this._service.Show(
"test",
"alo!",
MessageBoxServiceButton.OKCancel);
//if (_service.IsOpen == true)
//{
// MessageBoxResult rslt = _service.Result;
// if (rslt == MessageBoxResult.No)
// {
// MessageBox.Show("işlem iptal edildi");
// }
// else
// {
// MessageBox.Show("işlem onaylandı");
// }
//}
}
private void MessageBoxService_Closed(object sender, EventArgs e)
{
this._service.Closed -= this.MessageBoxService_Closed;
string rst = this._service.Result.ToString();
}