• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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
    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

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rafaelabe1977, Today, 03:51 AM
      1 response
      8 views
      0 likes
      Last Post sledge
      by sledge
       
      Started by inghkip17, Today, 06:25 AM
      0 responses
      3 views
      0 likes
      Last Post inghkip17  
      Started by inghkip17, Today, 06:23 AM
      0 responses
      3 views
      0 likes
      Last Post inghkip17  
      Started by xbdjvhbfvn, Today, 05:20 AM
      0 responses
      5 views
      0 likes
      Last Post xbdjvhbfvn  
      Started by jenifeery79, Today, 05:03 AM
      0 responses
      4 views
      0 likes
      Last Post jenifeery79  
      Working...
      X