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:
- Tab 1 & Tab 2 are both open, with Tab 1 being currently selected
- Tab 2 gets selected
- TabChange event of Tab 2 is called being the selected one
- TabChange event of Tab 1 is called being the deselected one
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();
}

Comment