【问题标题】:Show() window wait for a button to be pressed and mainWindow active (WPF)Show() 窗口等待按钮被按下并且 mainWindow 处于活动状态(WPF)
【发布时间】:2019-11-06 10:24:27
【问题描述】:

InteractiveWindow 包含“是”和“否”按钮。当前的解决方案是在MainWIndow 上显示InteractiveWindow,而无法访问MainWindowInteractiveWindow 也是 Window(不是 UserControl)。如何转换我的对话窗口以使我的InteractiveWindow 位于我的MainWindow 之上并能够访问MainWindow,直到按下两个按钮之一?

internal async Task<bool> Test()
{
      // some code

        var test= new InteractiveWindow();
        test.Owner = this;
        test.ShowDialog();

        // some other code
        return true;
}

其中一个按钮的旧代码:

private void YES_Click(object sender, RoutedEventArgs e)
{
    GetWindow(this).DialogResult = true;
    this.Close();
}

【问题讨论】:

    标签: wpf dialog


    【解决方案1】:

    你应该使用

    test.Show()
    

    而不是 test.ShowDialog(),因为 ShowDialog() 正在阻塞。即使你的方法是async,它也会同步执行,直到它需要await 一个不完整的Task,所以你的Test 方法是阻塞的,因为没有这样的await 语句。如果你不使用这个async修饰符,我建议你删除它。

    【讨论】:

      猜你喜欢
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      相关资源
      最近更新 更多