Floating window shows above on modal dialog.

Docking/MDI for WPF Forum

Posted 6 months ago by Yuki
Version: 23.1.3
Avatar

Hello,

Floating window sometimes shows above on modal dialog.

If there is any solution, please let me know.

  

  

Our application has 2 windows.

- MainWindow : includes DockSite

- SubWindow : has button which show toolwindow.

  

  

Procedure is the following.

0. Show toolwindow 

1. Float the toolwindow.

2. Close toolwindow.

3. Show SubWindow.

4. Press button (Show toolwindow)

--> ToolWindow will be shown above on SubWindow.

  

  

MainWindow.xaml

<Window
    x:Class="DockingWindowSample.MainWindow"
    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:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button
                x:Name="FloatToolWindowButton"
                Margin="8,0,0,0"
                Click="FloatToolWindowButton_Click"
                Content="(1) Float Right ToolWindow" />
            <Button
                x:Name="CloseToolWindowButton"
                Margin="8,0,0,0"
                Click="CloseToolWindowButton_Click"
                Content="(2) Close Right ToolWindow" />
            <Button
                x:Name="ShowDialogButton"
                Margin="8,0,0,0"
                Click="ShowDialogButton_Click"
                Content="(3) Show Dialog" />
        </StackPanel>

        <docking:DockSite x:Name="MyDockSite" Grid.Row="1">
            <docking:SplitContainer>

                <!--  Workspace  -->
                <docking:Workspace>
                    <docking:TabbedMdiHost>
                        <docking:ToolWindowContainer>
                            <docking:ToolWindow
                                Title="Fixed"
                                CanAttach="False"
                                CanDragTab="False"
                                HasTitleBar="False" />
                        </docking:ToolWindowContainer>
                    </docking:TabbedMdiHost>
                </docking:Workspace>

                <docking:ToolWindowContainer>
                    <docking:ToolWindow Title="Right" DefaultDockSide="Right" />
                </docking:ToolWindowContainer>
            </docking:SplitContainer>
        </docking:DockSite>
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace DockingWindowSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ShowDialogButton_Click(object sender, RoutedEventArgs e)
        {
            var window = new Window { Title = "Sub Dialog", ResizeMode = ResizeMode.NoResize, Height = 100, Width = 200 };
            var button = new Button { Content = "(4) Show ToolWindow", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
            button.Click += OnSubDialogButtonClicked;
            window.Content = button;
            window.ShowDialog();
        }

        private void OnSubDialogButtonClicked(object sender, RoutedEventArgs e)
        {
            var target = MyDockSite.ToolWindows.FirstOrDefault(x => x.Title == "Right");
            if (target != null)
            {
                target.Open();
            }
        }

        private void FloatToolWindowButton_Click(object sender, RoutedEventArgs e)
        {
            var target = MyDockSite.ToolWindows.FirstOrDefault(x => x.Title == "Right");
            if (target != null)
            {
                target.IsFloating = true;
            }
        }

        private void CloseToolWindowButton_Click(object sender, RoutedEventArgs e)
        {
            var target = MyDockSite.ToolWindows.FirstOrDefault(x => x.Title == "Right");
            if (target != null)
            {
                target.Close();
            }
        }
    }
}

[Modified 6 months ago]

Comments (1)

Answer - Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Behind the scenes, all we do with floating tool windows is create a WPF Window to host the tool window and set its Owner to the main Window.  You can see identical behavior in a new project without our products if you create a WPF Window that is owned by the main Window and show it in the same way.  Unfortunately since it's part of core WPF, we have no control over that behavior.

A possible workaround is to open the modal dialog as TopMost (to ensure it doesn't fall behind the main Window) and also call the modal dialog's Activate() method right after showing the tool window from it in OnSubDialogButtonClicked.


Actipro Software Support

The latest build of this product (v24.1.2) was released 4 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.