How to identify the focussed tab in multiple docked windows

Posted by: rambabu on 12 September 2023, 7:20 am EST

  • Posted 12 September 2023, 7:20 am EST - Updated 12 September 2023, 7:25 am EST

    I am looking to find the last focused tab when having multiple docked windows, as shown in the screenshot below.

    For instance, suppose I have 5 tabs within DockedWindow1 and 3 tabs within DockedWindow2. If my most recent interaction was with Tab 7 in DockedWindow2, I’d like to be able to identify the current active DockedWindow.

    Can you please let me know how to achieve this?

  • Posted 12 September 2023, 5:32 pm EST

    Hi Rambabu,

    You can create a variable to store the C1DockTabControl instance that fires the most recent SelectionChanged event. We have created a sample application that shows the implementation.

    Please check LastFocusedTab.zip for full implementation.

    Thanks & Regards,

    Aastha

  • Posted 13 September 2023, 2:40 am EST

    Hello Aastha,

    Thank you for the solution, but this doesn’t work as expected when you have only 1 tab in the Dockedwindow2.

    please refer to the video.

    https://www.awesomescreenshot.com/video/20735799?key=25aa95496d1f16b94bad12897aeb62ca

  • Posted 13 September 2023, 4:48 pm EST

    Hi Rambabu,

    As per our understanding, you want to fetch the C1DockTabControl associated with the last clicked C1DockTabItem. It should not be dependent on whether the selection is changed or not.

    In order to achieve the desired requirement, you can handle C1DockTabControl’s GotFocus event. Please refer to the following code snippet for the same:

    private void DockWindow_GotFocus(object sender, RoutedEventArgs e)
    {
        var ele = sender as C1DockTabControl;
        if (ele != null)
        {
            var focussedEle = ele.InputHitTest(Mouse.GetPosition(ele));
            if (focussedEle.GetType() == typeof(Border) && ((Border)focussedEle).TemplatedParent.GetType() == typeof(C1TabItemBorder))
            {
                _activeWin = ele;
            }
            else if (focussedEle.GetType() == typeof(TextBlock) && ((TextBlock)focussedEle).TemplatedParent.GetType() == typeof(ContentPresenter))
            {
                var parentEle = ((TextBlock)focussedEle).TemplatedParent as ContentPresenter;
                if (parentEle.TemplatedParent.GetType() == typeof(C1DockTabItem))
                {
                    _activeWin = ele;
                }
            }
        }
    }

    Kindly refer to the attached sample for full implementation. (See LastFocusedTab_Mod.zip)

    Thanks & Regards,

    Aastha

  • Posted 14 September 2023, 3:18 am EST

    Thanks a lot, Aastha.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels