Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NTTabPage lifecycle hooks for tab page creation and destruction?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NTTabPage lifecycle hooks for tab page creation and destruction?

    We have the OnWindowCreated(Window window) and OnWindowDestroyed(Window window) virtual methods on the AddOnBase for hooking into the NTWindow lifecycle, but are there any NTTabPage lifecycle hooks that allow me to intercept the creation and destruction of NTTabPage sub-classes?

    For example, in a Chart window when I click the "+" tab and create a new chart I want to intercept the creation of the ChartTab (a sub-class of NTTabPage) so I can set properties and subscribe to events on the newly created ChartTab. Similarly, I need to intercept the destruction of the ChartTab to unsubscribe events.

    Currently I'm subscribing to the INotifyCollectionChanged event of the NTWindow.MainTabControl.Items property like this:

    Code:
            protected override void OnWindowCreated(Window window)
            {
                base.OnWindowCreated(window);
    
                if (window is Chart chartWindow)
                {
                    var chartWindowMainTabControl = chartWindow.MainTabControl;
    
                    _tabControlCollectionView = CollectionViewSource.GetDefaultView(chartWindowMainTabControl.Items);
                    _tabControlCollectionView.CollectionChanged += TabControlOnCollectionChanged;
                }
            }
    ​
    But when a new tab is created and handled in the CollectionChanged event handler the TabItem.Content property is null and not set with the newly created ChartTab so there's no way to set its properties or subscribe to its events.

    Please advise how I can do this? Thanks.
    Attached Files

    #2
    Hello tcdouglas,

    You could use a Timer to get the added tab after it has loaded. The removed tab can be found using the event you have shown since it is already loaded. I have attached a small sample of finding the added tab.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    41 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    37 views
    0 likes
    Last Post CarlTrading  
    Working...
    X