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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      49 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      69 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      36 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      96 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      59 views
      0 likes
      Last Post PaulMohn  
      Working...
      X