Identifying visible tabs?

Docking/MDI for WPF Forum

Posted 6 years ago by Thomas Hutchinson
Version: 17.2.0665
Avatar

Hello

I am trying to determine whether a tab is visible to the user or not. The reason for this is that we have some complex UI logic which we only want to invoke if the tab is visible. I have written a test WPF app to attempt to figure this out.

 <docking:DockSite Name="DockSite"
                          WindowActivated="DockSite_OnWindowActivated"
                          WindowDeactivated="DockSite_OnWindowDeactivated"
                          FloatingWindowOpening="DockSite_OnFloatingWindowOpening">
            <docking:Workspace>
                <docking:DocumentWindow >
                    <docking:DockSite>
                        <docking:SplitContainer Orientation="Vertical">
                            <docking:ToolWindowContainer>
                                <docking:ToolWindow Title="Tab1">
                                    <TextBlock Text="This is tab 1"
                                               FontSize="32"
                                               VerticalAlignment="Center"
                                               HorizontalAlignment="Center"/>
                                    </docking:ToolWindow>
                                <docking:ToolWindow Title="Tab2">
                                    <TextBlock Text="This is tab 2"
                                               FontSize="32"
                                               VerticalAlignment="Center"
                                               HorizontalAlignment="Center"/>
                                    </docking:ToolWindow>
                                <docking:ToolWindow Title="Tab3">
                                    <TextBlock Text="This is tab 3"
                                               FontSize="32"
                                               VerticalAlignment="Center"
                                               HorizontalAlignment="Center"/>
                                </docking:ToolWindow>
                            </docking:ToolWindowContainer>
                        </docking:SplitContainer>
                    </docking:DockSite>
                </docking:DocumentWindow>
            </docking:Workspace>
        </docking:DockSite>

 Code behind:

using System.Diagnostics;
using System.Linq;
using System.Windows;
using ActiproSoftware.Windows.Controls.Docking;

namespace DockingSpike.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void DockSite_OnWindowActivated(object sender, DockingWindowEventArgs e)
        {
            Debug.WriteLine($"{e.Window.Title} activated");
        }

        private void DockSite_OnWindowDeactivated(object sender, DockingWindowEventArgs e)
        {
            Debug.WriteLine($"{e.Window.Title} deactivated");
        }

        private void DockSite_OnFloatingWindowOpening(object sender, FloatingWindowOpeningEventArgs e)
        {
            Debug.WriteLine($"floating");
        }
    }
}

 I've noticed that when a tab is floated then the other visible tab is deactivated. So this gets me half way there but not quite what I need. Is there a way to determine which tabs are visible?

[Modified 6 years ago]

Comments (4)

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

Hi Thomas,

I believe the simplest check for whether a docking window has a tab visible would be this:

var hasTabVisible = dockingWindow.ParentContainer?.IsTabStripVisible; 

Only docking windows with a "ParentContainer" potentially have tabs. 


Actipro Software Support

Posted 6 years ago by Thomas Hutchinson
Avatar

Ok, this tells me whether the parent element 

docking:ToolWindowContainer

has a visible tab but I want to determine whether or not each individual tab is visible...

docking:ToolWindow

 I have tried to determine whether a tab is visible with

 DockSite_OnWindowActivated

 

 private void DockSite_OnWindowActivated(object sender, DockingWindowEventArgs e)
 {
    Debug.WriteLine($"{e.Window.Title} activated");
    this.DetermineTabsVisibility();
 }

 private void DockSite_OnWindowDeactivated(object sender, DockingWindowEventArgs e)
 {
    Debug.WriteLine($"{e.Window.Title} deactivated");
    this.DetermineTabsVisibility();
 }

 private void DetermineTabsVisibility()
 {
   this.isTab1Visible = ToolWindow1.IsVisible;
   this.isTab2Visible = ToolWindow2.IsVisible;
   this.isTab3Visible = ToolWindow3.IsVisible;

   Debug.WriteLine($"Tab 1 is visible: {this.isTab1Visible}");
   Debug.WriteLine($"Tab 2 is visible: {this.isTab2Visible}");
   Debug.WriteLine($"Tab 3 is visible: {this.isTab3Visible}");
  }

 This almost works however IsVisible is not set until after DockSite_OnWindowActivated is invoked. Is there a more suitable event to use?

Thanks

[Modified 6 years ago]

Posted 6 years ago by Thomas Hutchinson
Avatar

Ok solved this by simply subscribing to the IsVisibleChanged events on the ToolWindows.

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

    ToolWindow1.IsVisibleChanged += ToolWindow1OnIsVisibleChanged;
  }    

   private void ToolWindow1OnIsVisibleChanged(object sender, 
    DependencyPropertyChangedEventArgsdependencyPropertyChangedEventArgs)
     {
       if (this.ToolWindow1.IsVisible)
       {
         Tab1TextBlock.Foreground = Brushes.Red;
       }
       else
       {
         Tab1TextBlock.Foreground = Brushes.Blue;
        }
       }
Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Thomas,

A ToolWindow in UI is the "container" of its content, it's not the UI "tab" itself.  That's why IsVisible is only true when the docking window is actually selected and visible.

Or if you were trying to determine if the actual UI "tab" is visible at all for a given docking window, my previous reply would apply.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.