c# - 未在任务栏中显示的 WPF ToolWindow 阻止应用程序

标签 c# wpf dialog taskbar

当您处于以下情况时会出现此问题: - 在我的应用程序中有一个主窗口 -我创建了另一个不在任务栏中显示的窗口,它是一个工具窗口。 - 我将第二个窗口显示为对话窗口(来自主窗口) - 我切换到另一个在我的系统中运行的应用程序,当我回到该应用程序时,主窗口显示,但它被第二个窗口锁定,没有显示。

这是第二个窗口的代码:

<Window x:Class="WpfApplication1.DialogWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="DialogWindow" Height="300" Width="300" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow" ShowInTaskbar="False">
   <!--Some content-->
</Windows>

这是显示第二个窗口的代码:

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

我怎样才能解决这个问题,并且仍然显示一个没有在任务栏中显示的对话框窗口?

最佳答案

我认为您应该将 DialogWindow.Owner 属性设置为父窗口。查看此答案 WPF: How do I set the Owner Window of a Dialog shown by a UserControl?

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    var dialogWindow = new DialogWindow();
    dialogWindow.Owner = Window.GetWindow(this)
    dialogWindow.ShowDialog();
}

这应该始终将 DialogWindow 模态地置于其父级之前。

关于c# - 未在任务栏中显示的 WPF ToolWindow 阻止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13385866/

相关文章:

c# - 将类对象绑定(bind)到 wpf 中的 ListView

c# - 使用 MVVM 将 RichTextBox 的内容保存到文件

wpf - 如何在WPF中隐藏Crystal Report的组树?

c# 控制台应用程序 - 防止默认异常对话框

java - SWT 标题区域对话框 : How to place a Button on the LEFT of ButtonArea?

c# - 解析 Json 返回字符串还是字符串数组?

C# WPF 使用转换器绑定(bind)路径数据

windows - 有没有办法从 Windows 批处理文件启动对话框?

c# - 使用 Over TCP 发送多个文件

c# - MonoDevelop - csproj 文件中的通配符