如何编程等待自定义MessageBox确定,取消,是,没有回复?

时间:2013-05-28 12:43:40

标签: c# windows-phone-7 parallel-processing windows-phone-8 task-parallel-library

如何编程等待自定义MessageBox确定,取消,是,没有回复?我一直在使用自定义messageBox因为我的自然语言,因为messagebox只有英文好,是的,没有我找到这个:Customizing MessageBox on 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消息框。但我的Costom MessageBox没有等待。如何锁定我的CustomMsgBox,直到单击ok-Cancel。

示例使用:

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();
}

0 个答案:

没有答案