Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
When closing the application...
posted

I want to iterate around the tabs in the XamTabcontrol and issue a close, so that they can each respond to the close and prompt the user to save changes.

 I can't see an obvious way to do this....help !

  • 54937
    Offline posted

    If you have added TabItemEx's to the Items collection you can just iterate the collection casting to that type and then calling its ExecuteCommand method with a parameter of TabItemExCommands.Close. There is a CloseAllTabs command as well but I'm assuming that you want to stop closing if one cancels the closing whereas that command will close all that do not cancel. A more generic version of what I described above would be something like:

            private void btnCloseAll_Click(object sender, RoutedEventArgs e)
            {
                CloseAll(this.xamTabControl1);
            }
     
            private static bool CloseAll(XamTabControl tabControl)
            {
                ItemContainerGenerator generator = tabControl.ItemContainerGenerator;
     
                for (int i = 0, count = tabControl.Items.Count; i < count; i++)
                {
                    TabItemEx tab = generator.ContainerFromIndex(i) as TabItemEx;
     
                    if (null != tab && tab.Visibility != Visibility.Collapsed)
                    {
                        if (false == tab.ExecuteCommand(TabItemExCommands.Close))
                            return false;
                    }
                }
     
                return true;
            }