Close alert in the Componentone docking

Posted by: rambabu on 2 August 2023, 7:34 am EST

    • Post Options:
    • Link

    Posted 2 August 2023, 7:34 am EST - Updated 2 August 2023, 7:53 am EST

    Hello,

    I am looking to implement an alert asking the user if they want to close all the windows in the component one Docktabcontrol, can you please let me know how to implement this?

    I tried doing it but it’s not working as intended, maybe I am using the wrong events for it.

    1. When it is floating. the title bar is getting black.

    I am using the IsVisibleChanged method to show the alert when the dock mode is hidden.

    1. when it is in the docked state, it closes directly.

    Is there any event that stops the hide event until the user confirms whether they want to close it?

  • Posted 2 August 2023, 10:43 pm EST

    Hi Rambabu,

    As per our understanding, you want to implement a feature in your sample application that allows users to close all docked and floating dock tab items when they click the ‘Yes’ button on a confirmation alert message box.

    Kindly refer to the attached sample for full implementation. (

    CloseAllDockTabItems.zip)

    In case your requirement differs from our understanding, please provide more details about the required behavior. It would be great if you could provide us with a gif/video to explain the desired behavior.

    Thanks & Regards,

    Aastha

  • Posted 3 August 2023, 12:41 am EST

    Hello Asha,

    I am looking for a requirement to show the alert message box when the user clicks on the close/hide icon of the C1DockTabcontrol.

    Let’s say we have 3 tabs in the C1DockTabControl and if I try to close/hide the C1DockTabControl, it should show an alert message box and ask if they want to close all the tabs in the control.

    Please let me know if there is a way to implement this.

  • Posted 3 August 2023, 10:47 pm EST

    Hi Rambabu,

    Thanks for giving a clearer understanding of your requirement.

    In order to achieve the desired behavior, you can handle the PreviewMouseLeftButtonDown event of the Close button present on the C1DockTabControl as shown in the following lines of code:

    private void dockTabControl_Loaded(object sender, RoutedEventArgs e)
    {
        var dockTabControl = sender as C1DockTabControl; 
        if (dockTabControl != null)
        {
            var hiddenButton = dockTabControl.Template.FindName("HiddenButton", dockTabControl) as Button;
            if (hiddenButton != null)
            {
                hiddenButton.PreviewMouseLeftButtonDown += (s, e) =>
                {
                    e.Handled = true;
                    var res = MessageBox.Show("Are you sure you want to close windows?", "Confirm Close", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (res == MessageBoxResult.Yes)
                    {
                        // closing all floating windows
                        foreach (var window in this.OwnedWindows)
                        {
                            var currentWindow = (WPFWindow)window;
                            if (currentWindow != null)
                            {
                                currentWindow.Close();
                            }
                        }
                        // closing all docked tabs
                        dockTabControl.Items.Clear();
                    }
                };
            }                
        }
    }

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

    Thanks & Regards,

    Aastha

  • Posted 4 August 2023, 3:49 am EST

    Thank you, Asha, for providing the solution quickly.

Need extra support?

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

Learn More

Forum Channels