Announcement

Collapse
No announcement yet.

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
    Excellent,thank you Jim

    Comment


      #3
      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 sender, KeyEventArgs e)
      {
        // FOCUS on ToolsBar's QuantitySelector TextBox
        TriggerCustomEvent(m =>
        {
          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


        #4
        Alternative Solution

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        546 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X