有时不显示ShowInputAsync

时间:2017-02-08 09:06:57

标签: wpf modal-dialog mahapps.metro

我在WPF php bin/console doctrine:database:create 中实现了一个界面,我想在[Doctrine\DBAL\Exception\ConnectionException] An exception occured in driver: SQLSTATE[08006] [7] FATAL: role "stats_crm" does not exist [Doctrine\DBAL\Driver\PDOException] SQLSTATE[08006] [7] FATAL: role "stats_crm" does not exist [PDOException] SQLSTATE[08006] [7] FATAL: role "stats_crm" does not exist 中调用Page,这是ShowInputAsync所在的位置。为此,我在MainWindow中引发事件并使用Page阻止函数:

Page

如果我尝试在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(); // ... } ,那就可以了:

ShowInputAsync

ItemPanel

如果我尝试从事件处理程序显示此对话框,则它不起作用。行后

MainWindow

代码返回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);

并显示没有任何对话框的窗口,所有Page都显示并启用,但我无法按下它们。

我还尝试将对话框放在一个单独的函数中,并使用/不使用OnMessageReceived.WaitOne(); 调用它,没有任何更改。

要在调用Control以阻止进一步执行代码后使用await,也没有帮助。

AutoResetEvent

还试图以这种方式调用单独的函数而没有结果:

Dialog

如何在事件处理程序中正确调用ShowInputAsync?或者我如何从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); 拨打ShowInputAsync

P.S。 Page中有MainWindowTabControl位于MainWindow的{​​{1}}

使用:

  • MahApps.Metro v1.4.1(NuGet包)
  • Windows OS 7
  • Visual Studio Express 2015
  • .NET Framework 4.5

UPD :简易示例为Image of the dialog

1 个答案:

答案 0 :(得分:0)

我找到了一个我正在使用的解决方案here

  

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

中定义