Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnTabCreate / OnTabDestroy for AddOns?

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

    OnTabCreate / OnTabDestroy for AddOns?

    Does anybody know how to code a tab equivalent of the OnWindowCreate/OnWindowDestroy methods that are available for NT8 AddOns?

    #2
    Hello gubbar924,

    You can add handlers to the Loaded and Closed events in the NTTabPage class.

    public class AddonWindowTabPage : NTTabPage
    {
    public AddonWindowTabPage()
    {
    Loaded += TabLoaded;
    Unloaded += TabUnloaded;
    }

    public void TabUnloaded(object sender, System.Windows.RoutedEventArgs e)
    {
    NinjaTrader.Code.Output.Process("tab is loaded", PrintTo.OutputTab1);
    }

    public void TabLoaded(object sender, System.Windows.RoutedEventArgs e)
    {
    NinjaTrader.Code.Output.Process("tab is unloaded", PrintTo.OutputTab1);
    }
    }

    This would be similar, except would trigger anytime the tab is actually being displayed (which is when the page or content for that tab loads) or being switched away from (which causes the content to unload).

    I will ask our development to see if there is something created specifically when the tab is created or closed instead of when loaded or unloaded.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello gubbar924,

      Our development has tipped be to the following document that demonstrates how to detect when the tabitems collection changes.
      I am trying to synchronize the selected tab item of a WPF tab control with the last item that was added. Since there is no such property as e.g. IsSynchedWithLastAddedItem, I am trying to detect w...


      This is general C# code and is not specific to NinjaTrader and is not documented in the NT8 help guide.

      The code, if added to the AddonShellWindow class would look like:

      In the Constructor() after the tabControl object is created and the TabControlManager methods run:
      Code:
      System.ComponentModel.ICollectionView myView = System.Windows.Data.CollectionViewSource.GetDefaultView(tabControl.Items);
      myView.CollectionChanged += TabsChanged;
      This would trigger a method within the AddonShellWindow class.
      Code:
      public void TabsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
      {
      	if (e.NewItems != null)
      	{
      		NinjaTrader.Code.Output.Process("new items: " + e.NewItems.Count.ToString(), PrintTo.OutputTab1);
      		System.Windows.Controls.TabItem newTab = e.NewItems[0] as System.Windows.Controls.TabItem;
      		NinjaTrader.Code.Output.Process("newTab: " + newTab.ToString(), PrintTo.OutputTab1);
      	}
      	if (e.OldItems != null)
      	{
      		NinjaTrader.Code.Output.Process("old items: " + e.OldItems.Count.ToString(), PrintTo.OutputTab1);
      		System.Windows.Controls.TabItem oldTab = e.OldItems[0] as System.Windows.Controls.TabItem;
      		NinjaTrader.Code.Output.Process("newTab: " + oldTab.ToString(), PrintTo.OutputTab1);
      	}			
      }
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CortexZenUSA, Today, 12:53 AM
      0 responses
      1 view
      0 likes
      Last Post CortexZenUSA  
      Started by CortexZenUSA, Today, 12:46 AM
      0 responses
      1 view
      0 likes
      Last Post CortexZenUSA  
      Started by usazencortex, Today, 12:43 AM
      0 responses
      2 views
      0 likes
      Last Post usazencortex  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      168 responses
      2,262 views
      0 likes
      Last Post sidlercom80  
      Started by Barry Milan, Yesterday, 10:35 PM
      3 responses
      11 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X