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

Loop through windows

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

    Loop through windows

    Hello,

    How can I loop through all open windows and dosomething on each window.

    I thought about a foreach within a dispatcher but I do not know how to access the list of open windows. I've put the foreach attempt below.

    foreach(Ninjatrader.Gui.Chart.Chart win in XXXXX)
    {
    win.Activate();
    //do something
    }

    I've tried "in System.Windows.Window" but this does not work.

    Please can you advise how to do this and how to access the list of open windows.

    Thanks

    #2
    Hello b16_aln,

    Thanks for your post.

    Please see below for a snippet demonstrating how to loop through active windows.

    Code:
    foreach (var window in NinjaTrader.Core.Globals.AllWindows)
    {
        // check if the found window is a Chart window, if not continue looking
        if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
    
        window.Dispatcher.InvokeAsync(new Action(() =>
        {
            // try to cast as a Chart, if it fails it will be null
            var foundChart = window as NinjaTrader.Gui.Chart.Chart;
    
            // make sure we found a chart
            if (foundChart == null) return;
    
            // make sure the found chart is the owner window
            if (foundChart != this.Owner as NinjaTrader.Gui.Chart.Chart) return;
        }));
    }
    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Excellent,thank you Jim

      Comment


        #4
        Originally posted by NinjaTrader_Jim View Post
        Hello b16_aln,

        Thanks for your post.

        Please see below for a snippet demonstrating how to loop through active windows.

        Code:
        foreach (var window in NinjaTrader.Core.Globals.AllWindows)
        {
        // check if the found window is a Chart window, if not continue looking
        if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
        
        window.Dispatcher.InvokeAsync(new Action(() =>
        {
        // try to cast as a Chart, if it fails it will be null
        var foundChart = window as NinjaTrader.Gui.Chart.Chart;
        
        // make sure we found a chart
        if (foundChart == null) return;
        
        // make sure the found chart is the owner window
        if (foundChart != this.Owner as NinjaTrader.Gui.Chart.Chart) return;
        }));
        }
        We look forward to assisting.
        Hello Jim and thanks for the guiding solution.

        I'm trying to adjust it to trigger foundChart.Focus() on the active window, from out of a quantity selector TextBox (not on the Charttrader, on the Toolbar).

        I've tried that but it's not getting the Focus out of the quantitySelector TextBox and into the Chart window.
        PHP Code:
        protected void ChartControl_PreviewKeyDown(object senderKeyEventArgs e)
        {
          
        // FOCUS on ToolsBar's QuantitySelector TextBox
          
        TriggerCustomEvent(=>
          {
            if (
        Keyboard.IsKeyDown(Key.Insert) && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
            {
              foreach (var 
        window in NinjaTrader.Core.Globals.AllWindows)
              {
                
        // check if the found window is a Chart window, if not continue looking
                
        if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;

                
        window.Dispatcher.InvokeAsync(new Action(() =>
                {
                  
        // try to cast as a Chart, if it fails it will be null
                  
        var foundChart window as NinjaTrader.Gui.Chart.Chart;

                  
        // make sure we found a chart
                  
        if (foundChart == null) return;

                  
        // make sure the found chart is the owner window
                  
        if (foundChart != this.Owner as NinjaTrader.Gui.Chart.Chart) return;

                  if (
        foundChart == this.Owner as NinjaTrader.Gui.Chart.Chart)
                    
        foundChart.Focus();
                }));
              }
            }

          }, 
        null);
          
        e.Handled true

        How else can I access the active window with focus? Thanks!

        Comment


          #5
          Alternative Solution

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by alifarahani, Today, 09:40 AM
          6 responses
          23 views
          0 likes
          Last Post alifarahani  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X