Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TabChangeHandler wrong timing?

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

    TabChangeHandler wrong timing?

    Hello there,

    I've been running into an error caused by a tab change. For some context, it's an indicator which adds custom controls to the chart trader and modifies the existing chart trader controls. This by itself works well and upon changing a tab all controls get restored just fine. The issue I'm facing is, when I have multiple tabs with the same indicator, the default charttrader controls get restored in the wrong order, causing issues when changing tabs again. What essentially happens is, that the event of the new tab being selected is called before the event of the tab that was deselected. Working with only custom controls doesn't lead to any issues, however when modifying the existing controls, including removing some, the removed controls are restored by the tab that was deselected only after the event of the selected tab has been executed.
    Basically:
    1. Tab 1 & Tab 2 are both open, with Tab 1 being currently selected
    2. Tab 2 gets selected
    3. TabChange event of Tab 2 is called being the selected one
    4. TabChange event of Tab 1 is called being the deselected one
    I'm using the basic tab change event handling as suggested in the examples:

    Code:
    private bool TabSelected()
            {
                bool tabSelected = false;
    
                // loop through each tab and see if the tab this indicator is added to is the selected item
                foreach (TabItem tab in chartWindow.MainTabControl.Items)
                    if ((tab.Content as Gui.Chart.ChartTab).ChartControl == ChartControl && tab == chartWindow.MainTabControl.SelectedItem)
                        tabSelected = true;
    
                return tabSelected;
            }
    
            private void TabChangedHandler(object sender, SelectionChangedEventArgs e)
            {
                if (e.AddedItems.Count <= 0)
                    return;
    
                tabItem = e.AddedItems[0] as TabItem;
                if (tabItem == null)
                    return;
    
                chartTab = tabItem.Content as Gui.Chart.ChartTab;
                if (chartTab == null)
                    return;
    
                if (TabSelected())
                    InsertWPFControls();
                else
                    RemoveWPFControls();
            }​
    Is there any way to ensure a "correct" order of event handling? I see it as a major flaw that based on the provided logic, first the newly selected tab fires the event before the deselected one does, since I have no way of ensuring that the default controls are properly restored before any other indicator or script in the other tab attempts to do anything with them.

    #2
    Hello Human#102,

    Unfortunately we cannot suggest modifying, removing or otherwise changing the default NinjaTrader controls for that reason. Your logic may work differently than how the original xaml or internal logic populated the overall control. The default controls would be internal code which we cannot look at to make a recommendation on a best approach. We can make suggestions on how to add or remove your own custom controls but we cannot provide suggestions on changing or removing platform controls. I would suggest to avoid removing any default controls or WPF structure to avoid this situation.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    605 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    351 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    560 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    561 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X