Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to check if Addon window already opened?

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

    How to check if Addon window already opened?

    Hi,

    I need to restrict the opening of an addon window to just one instance.

    If the addon window is already opened and the user clicks the New > MyAddon menu item again to open another window... I don't want the 2nd window to open. Is there a way to do that?

    TIA

    #2
    Hello defa0009,

    Thank you for your post.

    You could loop through all active windows and detect if another window is open.

    Here is a forum post with example code:

    https://forum.ninjatrader.com/forum/...te#post1101524

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      You could loop through all active windows and detect if another window is open.
      Perfect!!!

      Comment


        #4
        The other solution didn't really work for me but it helped me to figure out what I needed to do...

        In case anyone else is looking to limit the number of addon windows opened to one instance here is some skeleton code how to it...

        Code:
        namespace NinjaTrader.NinjaScript.AddOns {
        
            public class MyAddonWindow : NinjaTrader.NinjaScript.AddOnBase {
        
                private NTMenuItem newWindowMenuItem;
                
                private bool windowOpened = false;
        
                protected override void OnStateChange() {
        
                    // code goes here
                }
        
                protected override void OnWindowCreated(Window window) {
        
                    // code goes here
                }
        
                private void OnMenuItemClick(object sender, RoutedEventArgs e) {
        
                    if(windowOpened == false) {
                        
                        Globals.RandomDispatcher.InvokeAsync(new Action(() => new MasterWindow().Show()));
                        
                        windowOpened = true;
                    }
                }
        
                protected override void OnWindowDestroyed(Window window) {
        
                    if(newWindowMenuItem != null && window is ControlCenter) {
        
                        // code goes here
        ​
                    } else if(window is NTWindow) {
                        
                        NTWindow ntWin = window as NTWindow;
                        
                        if(ntWin != null && ntWin.Caption.Equals("MasterWindow"))
                            windowOpened = false;
                    }
                }
            }
        
            public class MasterWindow : NTWindow, IWorkspacePersistence {
        
                public MasterWindow() {
        
                    Caption = "MasterWindow";
                }
            }
        }
        ​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        30 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        47 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        38 views
        0 likes
        Last Post CarlTrading  
        Working...
        X