Wpf ShowInputSync有时不显示

Wpf ShowInputSync有时不显示,wpf,modal-dialog,mahapps.metro,Wpf,Modal Dialog,Mahapps.metro,我在WPF页面中实现了一个接口,我想在主窗口中调用showInputSync,这就是页面所在的位置。为此,我在页面中引发事件,并使用AutoResetEvent阻止函数: public AutoResetEvent OnMessageReceived; public void MessageReceived(object sender, PageReturnMessageEventArgs e) { try { if (e.ToString() == "Canc

我在WPF
页面
中实现了一个接口,我想在
主窗口
中调用
showInputSync
,这就是
页面
所在的位置。为此,我在
页面
中引发事件,并使用
AutoResetEvent
阻止函数:

public AutoResetEvent OnMessageReceived;

public void MessageReceived(object sender, PageReturnMessageEventArgs e)
{
    try
    {
        if (e.ToString() == "Cancel" || string.IsNullOrEmpty(e.ToString()))
        {
            throw new Exception("Exception of parsing of hours");
        }
    }
    catch (Exception ex)
    {
        // log it
    }
    this.OnMessageReceived.Set();
}

private void Page_OnNextPageClick(object sender, EventArgs e)
{
    // ...

    MessageShow("Additional information", "How much time will this SuperProcess take?", "HOURS");

    OnMessageReceived.WaitOne();
    OnMessageReceived.Reset();

    // ...
}
如果我尝试从
main窗口中的任何函数显示
ShowInputAsync
,它会工作:

MetroDialogSettings s = new MetroDialogSettings();
s.AffirmativeButtonText = @"Create";
s.NegativeButtonText = @"Cancel";
s.AnimateShow = true;
var result = await this.ShowInputAsync("Test", "TestMessage", s);

if (result == null)
{ return; }

如果我试图从事件处理程序中显示此对话框,它将不起作用。下线

var result = await this.ShowInputAsync("Test", "TestMessage", s);
代码毫无例外地返回到
页面
,执行第行

OnMessageReceived.WaitOne();
显示窗口时没有任何对话框,所有
控件都显示并启用,但我无法按它们

我还尝试将对话框放在一个单独的函数中,并在有/没有
wait
的情况下调用它,但没有任何变化

调用
对话框后使用
AutoResetEvent
来阻止代码的进一步执行也没有帮助

private AutoResetEvent OnMessageReturning;
var result = await this.ShowInputAsync(e.Title, e.Message, s);
OnMessageReturning.WaitOne();
还尝试以这种方式调用分离函数,但没有结果:

CancellationToken token;
TaskScheduler uiSched = TaskScheduler.FromCurrentSynchronizationContext();
await Task.Factory.StartNew(SeparateFunction, token, TaskCreationOptions.None, uiSched);
如何在事件处理程序中正确调用ShowInputSync?或者如何从
main窗口中的
Page
调用
ShowInputAsync

另外,在
主窗口中有
选项卡控件
页面
放在一个
选项卡项

使用:

  • MahApps.Metro v1.4.1(NuGet软件包)
  • WindowsOS7
  • Visual Studio Express 2015
  • .NET Framework 4.5
UPD:Easy sample is

我找到了我正在使用的解决方案:

TryFindParent是在MahApps.Metro.Controls.TreeHelper中定义的扩展方法,ShowMessageAsync是在MahApps.Metro.Controls.Dialogs.DialogManager中定义的


我上传到GitHub,链接在上面,谢谢。