We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to set TabControlExt default at either runtime or design time when you don't explicitly define it in XAML

Please can you provide details on how to set the TabControlExt CloseMode default at either runtime or design time. I add new tabs at runtime based on user controls but can't find how to access the TabControlExt as I don't specify this myself.
My aim is to delete children rather than hide them
I add tabs like this (TableEditor is a User Control):
var newTable = new TableEditor(_selectedTableName) { Name = "TableEditor" + _selectedTableName };

TablesDockingManager.BeginInit();
DockingManager.SetDockingManager(newTable, TablesDockingManager);
DockingManager.SetHeader(newTable, "Table " + _selectedTableName);
DockingManager.SetState(newTable, DockState.Document);
DockingManager.SetDesiredMinWidthInDockedMode(newTable, 200);
TablesDockingManager.Children.Add(newTable);
TablesDockingManager.EndInit();
I tried following the notes here: https://www.syncfusion.com/kb/3605/how-to-update-the-tabitemcollection-when-any-one-of-its-tabitem-gets-closed
But this is aimed at having the TabControlExt defined at design time
thanks
Craig

10 Replies

VR Vijayalakshmi Roopkumar Syncfusion Team May 10, 2016 12:23 PM UTC

 Hi Craig,

Thank you for using Syncfusion Products.

By default, TabItemExt in TabControlExt will not be removed from memory when we close the TabItem and its instances are maintained in memory. To clear the TabItemExt instance from memory, we need to set CloseMode as Delete. But it will not remove the child from Children collection of DockingManager. We can remove the child from Children collection of DockingManager by removing it from the children collection manually when the DockState is changed to Hidden. Please refer to the following code example.
DockingManager as shown in the following code example:  
 
private void TableDockingManager_DockStateChanged(FrameworkElement sender, DockStateEventArgs e) 
{ 
if(e.NewState == DockState.Hidden) 
{ 
 
// Used to remove the children from the DockingManager 
 
TableDockingManager.Children.Remove(sender); 
} 
 
} 
 
 

Please find the sample from the following link:

Sample: TabControlExt_124023

Regards,
Vijayalakshmi V.R.

 



CG Craig Greenway May 10, 2016 02:35 PM UTC

Thank you


CG Craig Greenway May 10, 2016 06:05 PM UTC

Sorry, I wanted to check a window is allowed to close before I close it so implemented the OnDockStateChanging, but setting e.Cancel to true still closes document, should the following prevent the document closing?

        private void DockingManager_OnDockStateChanging(FrameworkElement sender, DockStateChangingEventArgs e)
        {
            //hidden tabs will be removed completely, but check if need to save first
            if (e.TargetState == DockState.Hidden)
            {
                if (sender.GetType() == typeof(TableEditor))
                {
                    e.Cancel = true;
                }
            }
        }


VR Vijayalakshmi Roopkumar Syncfusion Team May 11, 2016 09:05 AM UTC

Hi Craig,

In our DockingManager, we can restrict the closing of the Document children by handling the CloseButtonClick event. To prevent the Dock window from closing, the WindowClosing Event can be used. The code example below depicts the same.  
  

private void TableDockingManager_CloseButtonClick(object sender, CloseButtonEventArgs e) 
{ 
//Handles the closing of Document child  
e.Cancel = true; 
 
} 
 
 
The same has been demonstrated in our sample, please download it from the following location:

Sample: TabControlExt_124023_Modified
 

Regards,
Vijayalakshmi V.R.  
  



CG Craig Greenway May 12, 2016 05:02 AM UTC

Hello,

The CloseButtonClick event is great when you close one document, but I was using the OnDockStateChanging e.Cancel intentionally as if you right click, close all for example the CloseButtonClick doesn't get fired.  I need an event when closing all where I can cancel the closing process.  Setting OnDockStateChanging e.Cancel to True should work but doesn't?


CG Craig Greenway May 12, 2016 05:17 AM UTC

So here is a visual of what is happening when you set e.Cancel to true in the OnDockStateChanging  event.  The docked tab becomes half-closed, half-open.  In the bottom screenshot you can see the rounded border.  If I try add a new window, the old one is still present but you can't dock it.  As a reminder, the docked window is based on a simple user control. Hope this helps?

Before and after


VR Vijayalakshmi Roopkumar Syncfusion Team May 13, 2016 12:41 PM UTC

Hi Craig,

Query#1: The CloseButtonClick event is great when you close one document, but I was using the OnDockStateChanging e.Cancel intentionally as if you right click, close all for example the CloseButtonClick doesn't get fired. I need an event when closing all where I can cancel the closing process. Setting OnDockStateChanging e.Cancel to True should work but doesn't?
To cancel the closing of all document tabs in DockingManager, you can use the DocumentClosing event of DocumentContainer. The same has depicted in the following code:  
(TableDockingManager.DocContainer as DocumentContainer).Loaded += MainWindow_Loaded;  
  
void MainWindow_Loaded(object sender, RoutedEventArgs e)  
{  
(TableDockingManager.DocContainer as DocumentContainer).DocumentClosing += MainWindow_DocumentClosing;  
}  
  
void MainWindow_DocumentClosing(object sender, CancelingRoutedEventArgs e)  
{  
e.Cancel = true;  
}  
  
  


Query#2:So here is a visual of what is happening when you set e.Cancel to true in the OnDockStateChanging event. The docked tab becomes half-closed, half-open. In the bottom screenshot you can see the rounded border. If I try add a new window, the old one is still present but you can't dock it. As a reminder, the docked window is based on a simple user control. Hope this helps?

We have tried closing the document and docked window by setting e.Cancel to true in DockStateChanging event, but we were unable to replicate the half closed and half-open issue. Could you please get back to us with modified sample reproducing the issue along with replication steps, it would be helpful for us to proceed further on this.

Sample:TabControlExt_124023_ModifiedNEW


Regards,
Vijayalakshmi V.R.
 



CG Craig Greenway May 14, 2016 07:34 AM UTC

Hello,

The DocumentClosing is the correct place for me to handle the checking if you can close the window, thank you for this.  In terms of the screenshot, I'm guessing this was due to DocumentClosing not being cancelled so part of the TDI window was being closed before the OnDockStateChanging event fired.  I have all the information I need now.

When I looked in the sample project for tabs, there was no code for handling closing window events.  Perhaps if this thread could be used to add additional code to the sample project (for example in the text editor if you change it, mark the window Dirty and check when closing) this could help others in the future

thanks again

Craig


CG Craig Greenway May 14, 2016 09:06 AM UTC

Spoke too soon!

If you have 2 TDI windows open and right-click, close all, the DocumentClosing event is called twice per TDI window (so 4 times).  With 3 windows open, you get 6 DocumentClosing events.  I am really struggling to find an event where I can prompt the user to see if they want to close the TDI window, but only prompt them once.


VJ Victory Jessie Selvam D Syncfusion Team May 16, 2016 08:07 AM UTC

Hi Craig,

Query #1: In terms of the screenshot, I'm guessing this was due to DocumentClosing not being cancelled so part of the TDI window was being closed before the OnDockStateChanging event fired. I have all the information I need now.
If document tab closing is cancelled using DockStateChanging event, then tab item will be removed from TabControlExt before DockStateChanging event cancels the item closing. So it causes TDI windows to remain half closed and half open.We suggest you to use DocumentClosing event to cancel the document tab closing.

Query #2: When I looked in the sample project for tabs, there was no code for handling closing window events. Perhaps if this thread could be used to add additional code to the sample project (for example in the text editor if you change it, mark the window Dirty and check when closing) this could help others in the future.
We have modified the sample using checkbox in UserControl(TableEditor) which determines whether a document tab can be closed or not. You can download the sample from following link:

Sample: TabControlExt_124023_DocumentClosing

Query #3: If you have 2 TDI windows open and right-click, close all, the DocumentClosing event is called twice per TDI window (so 4 times). With 3 windows open, you get 6 DocumentClosing events. I am really struggling to find an event where I can prompt the user to see if they want to close the TDI window, but only prompt them once.
We were able to reproduce the reported issue "DocumentClosing event fires twice for a document while using CloseAll option" and logged a defect report for this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents  

Please let us know if you have any questions.

Regards,
Jessie

Loader.
Live Chat Icon For mobile
Up arrow icon