I am currently working on a project involving NinjaTrader, where I need to programmatically interact with the UI, specifically to automate certain actions in the Control Center. My goal is to programmatically select and open the "Tools" menu and then the "Options" item within it.
Despite various attempts using NinjaScript, I've encountered challenges in simulating click events on the menu items. Methods such as raising click events programmatically and setting IsPressed on NTMenuItem have not yielded the desired result. It appears that these menu items do not respond to artificial click events in the same way as user-initiated ones.
I am reaching out to seek advice or alternative solutions for this task. Are there specific methods or approaches within NinjaTrader's framework that would facilitate this type of UI interaction? Any guidance or suggestions from the community or NinjaTrader's support team would be greatly appreciated.
Current Code is an AddOnBase class:
protected override void OnWindowCreated(Window window) { Print($"window name: {window}"); controlCenter = window as Gui.ControlCenter; if (controlCenter != null) { Print($"control center content: {controlCenter.Content}"); FindToolsMenueItem(controlCenter); } } private async void FindToolsMenueItem(DependencyObject parent, int depth = 0) { int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { var child = VisualTreeHelper.GetChild(parent, i); // Check if the child is a ListBoxItem if (child is NTMenuItem toolsMenuItem) { // Print($"Control Center Child: {toolsMenuItem}, Name: {toolsMenuItem.Name}"); if (toolsMenuItem.Name == "toolsMenuItem") { Print("Found toolsMenuItem"); // toolsMenuItem.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent)); toolsMenuItem.IsSubmenuOpen = true; await Task.Delay(100); // toolsMenuItem.IsPressed = true; FindOptionsMenuItem(toolsMenuItem); break; } } // Recurse into the child FindToolsMenueItem(child, depth + 1); } } private async void FindOptionsMenuItem(DependencyObject toolsMenuItem) { int childrenCount = VisualTreeHelper.GetChildrenCount(toolsMenuItem); for (int i = 0; i < childrenCount; i++) { var child = VisualTreeHelper.GetChild(toolsMenuItem, i); // Print($"Options child: {child}"); if (child is System.Windows.Controls.Primitives.Popup popUp ) { FindOptionsMenuItem(popUp.Child); break; } if (child is NTMenuItem optionsMenuItem && optionsMenuItem.Header == "Options") { Print("Found the option menu item"); // optionsMenuItem.RaiseEvent(new RoutedEventArgs(NTMenuItem.ClickEvent)); // Doesnt Work optionsMenuItem.IsPressed = true; // Doesnt Compile because the set accessor is inaccessible } // Recurse if needed FindOptionsMenuItem(child); } }
Also, I'm doing all of this in order to completely disable "Use order entry hot keys", if there's any way programmatically to disable this option without needing to snoop through all the UI elements that would be much better than what i did.
Thank you for your assistance and for providing a platform that offers such extensive customization capabilities.
Best regards, Aviram Y
Comment