简体   繁体   English

WPF ShowDialog与另一个活动窗口

[英]WPF ShowDialog with another Window Active

When my MainWindow starts, I automatically show a 2nd "CountdownWindow". 当我的MainWindow启动时,我会自动显示第二个“ CountdownWindow”。 The CountdownWindow is TopMost. CountdownWindow是TopMost。

MainWindow和CoutdownWindow

While both the Main and Countdown windows are shown the user can click a button to launch a 3rd Modal Window with ShowDialog. 当同时显示主窗口和倒计时窗口时,用户可以单击按钮以使用ShowDialog启动第三个模态窗口。

对话框窗口处于活动状态,但CountdownWindow未处于活动状态

While the Dialog is active, I would like the user to be able to also interact with the topmost CountdownWindow (ie, minimize, maximize, close it or move it around), however this is not possible. 当对话框处于活动状态时,我希望用户也可以与最顶部的CountdownWindow进行交互(即,最小化,最大化,关闭或移动它),但是这是不可能的。

Would launching the Dialog window from a separate process or a separate thread solve this problem? 从单独的进程或单独的线程启动“对话”窗口是否可以解决此问题?

Here are the relevant parts of my code if you need it 如果需要,这是我代码的相关部分

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        var dialogWindow = new DialogWindow();
        dialogWindow.ShowDialog();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        var countDownWindow = new CountdownWindow();
        countDownWindow.Owner = this;
        countDownWindow.Show();
    }
}

<Window x:Class="WpfTestBase.CountdownWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfTestBase"
    mc:Ignorable="d"
    Topmost="True"
    Title="CountdownWindow TopMost=True" Height="300" Width="400">
<Grid>

</Grid>

Instead of Dialog.ShowDialog() why don't you just set the Dialog.Owner = MainWindow, then Dialog.Show()? 为什么不只设置Dialog.Owner = MainWindow,然后设置Dialog.Show(),而不是Dialog.ShowDialog()? It will then stay on top of the main window, but will not block the main thread as it does with ShowDialog(). 然后它将停留在主窗口的顶部,但不会像ShowDialog()那样阻塞主线程。 The whole point of ShowDialog is to be modal, and block the main UI thread. ShowDialog的全部要点是模态的,并阻塞UI主线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM