Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot Get Access to WPF Control

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

    Cannot Get Access to WPF Control

    Hello,
    I added two TextBoxes to charttrader. I now want to access them from a darawing tool. I'm making an error in the code to access them. Here is what I've tried.

    I don't know what to instantiate MyControl with in the first selection:
    Code:
      
      foreach (DependencyObject item in MyControl)
    ​
       Print(string.Format("AutomationId: {0} | item: {1}", System.Windows.Automation.AutomationProperties.GetAutomationId(item), item));
    
       if (System.Windows.Automation.AutomationProperties.GetAutomationId(item) == "MyObjectsAutomationId")
    
           Print("found my object");
    }​
    
                chartTraderGrid = (chartWindow.FindFirst("ChartWindowChartTraderControl") as Gui.Chart.ChartTrader).Content as System.Windows.Controls.Grid;
    
                TextBox tb = chartTraderGrid.FindFirst("textBox00") as TextBox;
                      
                TextBox textBox01 = Window.GetWindow(ChartControl.Parent).FindFirst("textBox00") as TextBox;
    ​
    The other attempts result in null. I've attached a screen shot of the controls as shown in Inspect.

    Thanks in advance.
    Attached Files

    #2
    Hello ramckay,

    Are you setting an automationId on the TextBox with System.Windows.Automation.AutomationProperties.Set AutomationId()?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      The answer is no. I had not set automation IDs. I added them and did repeated queries to locate the TextBoxes. For some reason, locating the controls is intermittent. The TextBoxes were placed into a grid which is added to the ChartTrader Grid. I gave the grid a UI ID as well. The location problem may have been related to running Snoop and Inspect repeatedly. NT often crashes when either of the apps are running. Will let you know if further problems develope.
      Thanks,
      Rod

      Comment

      Latest Posts

      Collapse

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