What is a good way to AutoHide the TitleBar of ToolWindow?

Docking/MDI for WPF Forum

Posted 2 years ago by Kim Jiho - Ansys
Version: 22.1.3
Avatar

Hello,

We inherited ToolWindow and added features to automatically hide TitleBar.

public class CustomToolWindow : ToolWindow
{
    public bool UseAutoHideTitleBar
    {
        get { return (bool)GetValue(UseAutoHideTitleBarProperty); }
        set { SetValue(UseAutoHideTitleBarProperty, value); }
    }

    public static readonly DependencyProperty UseAutoHideTitleBarProperty =
        DependencyProperty.Register(nameof(UseAutoHideTitleBar), typeof(bool), typeof(CustomToolWindow), new PropertyMetadata(false));

    public CustomToolWindow(DockSite dockSite, string serializationId, string title, ImageSource imageSource, object content)
        : base(dockSite, serializationId, title, imageSource, content)
    {
    }

    protected override void OnVisualParentChanged(DependencyObject oldParent)
    {
        base.OnVisualParentChanged(oldParent);

        if (this.UseAutoHideTitleBar && this.Parent is ToolWindowContainer toolWindowContainer)
        {
            toolWindowContainer.MouseEnter -= OnMouseEnter;
            toolWindowContainer.MouseEnter += OnMouseEnter;

            toolWindowContainer.MouseLeave -= OnMouseLeave;
            toolWindowContainer.MouseLeave += OnMouseLeave;

            void OnMouseEnter(object sender, MouseEventArgs e)
            {
                if (sender is ToolWindowContainer toolWindowContainer)
                {
                    var selectedToolWindow = toolWindowContainer.SelectedToolWindow;
                    selectedToolWindow.HasTitleBar = true;
                }
            }

            void OnMouseLeave(object sender, MouseEventArgs e)
            {
                if (sender is ToolWindowContainer toolWindowContainer)
                {
                    var window = toolWindowContainer.SelectedToolWindow;

                    if (window != default)
                    {
                        window.HasTitleBar = false;
                    }
                }
            }
        }
    }
}

Link

It works similarly to what we expected, but there's a little bit of a problematic.

It blinks when I float the ToolWindows and over the mouse.

Please refer to the video on the link.

Please let me know if there is a good way for you.

Thank you.

 
 

[Modified 2 years ago]

Comments (1)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I took your code and debugged with it.  What happens when you float a ToolWindowContainer is that we tell Windows behind the scenes that it can hit-test the title bar portion of the ToolWindowContainer as a non-client title bar.  Windows' Win32 hit-testing logic intercepts when the mouse is over that (so things like drags and context menus work like on a normal Window title bar) and that triggers WPF to think the mouse "left" the title bar element.  Thus the title bar auto-hides.  Then once hidden, it gets a mouse enter message again on the next move so it shows again and repeats the flickering.

Unfortunately we need to support Win32 as we do to support proper title bar functionality for floating tool windows, so I'm not sure there's any possible workaround here.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.