Search code examples
c#wpfdialogtaskbar

WPF ToolWindow that is not showed in taskbar block the application


This is a problem that happens when you are in the follow situation: -Have a main window in my application -I create another window that doesn't show in task bar, and is a tool window. -I show the second window as a dialog window (from the main window) -I switch to another application running in my system, and when i came back to the application the main window is showed, but it is locked by the second windows, that is not showed.

This is the code of the second window:

<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>

And this is the code that shows the second window:

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

How can i solve this problem, and still showing a dialog windows that doesn't shows in task bar?


Solution

  • I think you should set the DialogWindow.Owner property to the parent window. See this answer 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();
    }
    

    That should put the DialogWindow modally in front of its parent at all times.