Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Which tab is active (got focus) for Addon

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

    Which tab is active (got focus) for Addon

    Hi All,

    Hopefully quick question here. I have an addon based on the basic script https://ninjatrader.com/support/help...t_overview.htm

    From within class AddOnFrameworkTab how can i tell which tab is active (ie. has got the focus)?

    Thanks
    Last edited by Bidder; 04-08-2021, 10:56 PM.

    #2
    Hello Bidder,

    Could you provide more detail on what you need to know the tab is active for? The AddOnFrameworkTab class is created and then used but it would not its self know if its active or not. The TabManager would be able to see those changes using its SelectionChanged event.

    You may be able to use an individual controls IsFocused property depending on what the use case is.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Right, so each tab is processing OnMarketData() events and the only control on the tab is a System.Windows.Controls.DataGrid which displays the resulting data. DataGrid has an IsFocused property but it seems to always return false no matter which tab is selected.

      Comment


        #4
        Hello Bidder,

        I still don't understand what the need to know if its focused or not is, if you subscribe to data it should remain subscribed until the addon is terminated. The Addon sample from the help guide demonstrates the correct way to cleanup resources and unsubscribe from market data in that context.

        Can you provide more detail on what your goal is or why you need to know which tab is active?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          The reason is there is an instrument selector on the "title bar" and it needs to know which tab to operate on.

          I got the selection changed function event working. So now the function can tell that the tab has changed. How, now can I identify which tab was changed to. That will be the final piece in the puzzle. Persistance Id identifies the tab uniquely but it does not appear to be available on tab control.



          Code:
          TabControl tc = new TabControl();
          tc.SelectionChanged += OnSelectionChanged;
          
          public void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
          {
          TabControl t = sender as TabControl;
          }

          Comment


            #6
            Hello Bidder,

            The instrument selector should be moved from the titlebar into the tab contents like the sample we provide, that would allow each tab to know which instrument is being used. If you place the instrument selector outside of the tab content then that would really only allow for a window without tabs to be used and it would just have 1 instrument selector to control the whole window.

            The tab control has other properties like a selected index, you may be able to use that to delegate some custom logic however unsubscribing from the instrument and other cleanup would also need to be added in your own custom way based on how your window worked. It would be easiest to just copy the existing working code from the tab sample in the help guide.


            I look forward to being of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              I am not interested in rewriting the application. That would be too time consuming.

              Can you please help with the question which has been asked. ?

              Comment


                #8
                Hello Bidder,

                You can likely accomplish what you are asking but you would need to work through each problem you see as you run into it. The first would be assigning instruments to tabs after the selector has selected an instrument. The next step would be checking what you made works with saving/restoring workspaces and making sure the subscription is both unsubscribed and resubscribed at the correct times.

                You would still need to follow the sample in the help guide exactly for how the Instrument is defined in the tab and not in the window. That also includes all subscription logic and workspace related logic in the tab.

                From outside the tab you would have to locate the tab in question and then access the public Instrument property to set it to what you selected. You may be able to use the SelectedIndex for that purpose to know which tab is currently selected. You could use the tab controls items collection to find an item and cast it to the appropriate type to access its properties to set the instrument.

                As I don't have any samples of that concept I couldn't really provide in depth suggestions here other than you will need to explore this and create a custom solution for your intended goal, it will be less time consuming to redo the tool in the same way as the addon sample because that's already built with the correct working code.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9

                  Jesse, Thanks for your suggestion about the TabControl SelectionChanged event which was key to the determination of which tab was active. Once the active tab is known the linkage is then made using the unique persistance id.


                  Code:
                  // TabControl should be created for window content if tab features are wanted
                  TabControl tc = new TabControl();
                  tc.SelectionChanged += OnSelectionChanged;
                  Code:
                  private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
                  {
                      TabControl t = sender as TabControl;
                      foreach (TabItem tab in t.Items)
                      {
                         var AddonTab = tab.Content as AddOnFrameworkTab;
                         if (tab.IsSelected)
                         {  
                              ActiveTabId=AddonTab.PersistenceId;
                              ActiveTabName=AddonTab.TabName;
                        }
                     }
                  }

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Stanfillirenfro, Today, 07:23 AM
                  2 responses
                  9 views
                  0 likes
                  Last Post Stanfillirenfro  
                  Started by rexsole, Today, 08:39 AM
                  2 responses
                  6 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by cmtjoancolmenero, Yesterday, 03:58 PM
                  6 responses
                  29 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by gbourque, Today, 06:39 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post gbourque  
                  Started by trilliantrader, Yesterday, 03:01 PM
                  3 responses
                  31 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X