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

Gui.Tools.WorkspaceOptions.SwitchToWorkspace

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

    Gui.Tools.WorkspaceOptions.SwitchToWorkspace

    What is the proper way in NinjaTrader 8 to use NinjaTrader.Gui.Tools.WorkspaceOptions.SwitchToWor kspace(string workspaceName)?

    I created a test indicator that will execute NinjaTrader.Gui.Tools.WorkspaceOptions.SwitchToWor kspace("wsTest");, which partially works. The workspace will switch, but several chart windows from the workspace that executed SwitchToWorkspace will persist in the workspace I switched to ("wsTest")

    #2
    Hello Jack22, thanks for your note.

    Using this class is not officially supported, it is likely that the NinjaTrader core does some extra steps and uses that SwitchToWorkspace to properly switch a workspace. I tested the same thing and received the same result where there were residual windows from the old workspace. I can submit a feature request to have this exposed to the public NinjaScript library.

    Thanks in advance for your patience.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Since this is not officially supported, I am adding what is working for me right now:

      Code:
      if (button != null)
      {
          string wsActivate = button.Content.ToString(); // Workspace I want to switch to
          string wsDeactive = NinjaTrader.Gui.Tools.WorkspaceOptions.GetActiveWorkspaceFromXml; // Current active workspace
      
          if(wsActivate != wsDeactive)
          {
              // I get errors when calling Switch before Close
              NinjaTrader.Gui.Tools.WorkspaceOptions.CloseWorkspace(wsDeactive, true, false, false);
              NinjaTrader.Gui.Tools.WorkspaceOptions.SwitchToWorkspace(wsActivate);
          }
      }

      Comment


        #4
        Originally posted by Jack22 View Post
        Since this is not officially supported, I am adding what is working for me right now:

        Code:
        if (button != null)
        {
        string wsActivate = button.Content.ToString(); // Workspace I want to switch to
        string wsDeactive = NinjaTrader.Gui.Tools.WorkspaceOptions.GetActiveWorkspaceFromXml; // Current active workspace
        
        if(wsActivate != wsDeactive)
        {
        // I get errors when calling Switch before Close
        NinjaTrader.Gui.Tools.WorkspaceOptions.CloseWorkspace(wsDeactive, true, false, false);
        NinjaTrader.Gui.Tools.WorkspaceOptions.SwitchToWorkspace(wsActivate);
        }
        }

        Very helpful. Thank you

        Comment


          #5
          Hi All,
          After experimenting with the functions in Jack's post it became apparent they were lacking in some functionality.

          They perform the anticipated action but leave the Workspace menu in a wonky state. Meaning the workspace menu no longer reflects which menus are open, active, closed etc. My requirements are only to open/switch the workspaces-that is all. If you need to do other operations this
          may not work for you.

          I have this code in an addon so the first step is to get the control center window object. After that the code will read through the list of workspaces currently on the workspace menu and invoke a click event on the matching entry. Clean, simple.

          I anticipating the customary dour comment from NT because this is not in the view of their 2mm lens.

          It works for me, I share it with you. Code responsibly.


          Code:
                  public static void OpenWorkspace(string WsName)
                  {
                      ccWindow.Dispatcher.InvokeAsync(() =>
                      {
                          NTMenuItem WorkspacesMenuItem;
                          WorkspacesMenuItem = ccWindow.FindFirst("ControlCenterMenuItemWorkspaces") as NTMenuItem;
                          if (WorkspacesMenuItem != null)
                          {
                              for (int i = 0; i < WorkspacesMenuItem.Items.Count; i++)
                              {
                                  NTMenuItem Nmi = WorkspacesMenuItem.Items[i] as NTMenuItem;
                                  
                                  if (Nmi.Header.ToString()==WsName)
                                  {
                                       Nmi.RaiseEvent(new RoutedEventArgs(NTMenuItem.ClickEvent));
                                  }
                              }
                          }
                      });
                  }​

          Get control center window object:
          Code:
          private static ControlCenter ccWindow;
          
          protected override void OnWindowCreated(Window window)
                  {
          
                      ControlCenter cc = window as ControlCenter;
                      if (cc == null)    return;
                      ccWindow=cc;
          
                  }​


          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Skifree, Today, 03:41 AM
          3 responses
          12 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by traderqz, Yesterday, 09:06 AM
          5 responses
          32 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by guillembm, Today, 11:25 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by owensd, 04-21-2024, 11:34 PM
          9 responses
          34 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by trilliantrader, 04-10-2024, 09:33 PM
          7 responses
          25 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X