Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Clicking on XAML button of Add-On from an Indicator

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

    Clicking on XAML button of Add-On from an Indicator

    Hello,

    Is it possible to click on XAML add-on button from an indicator? Indicator could find add-on window and click on button within this GUI Add-On (basically any kind of XAML window)...

    Any 3rd party tools you would recommend on using like Microsoft UI Automation library in .Net 4.5 etc..?

    Thanks

    #2
    Hello music_p13,

    Thank you for your post.

    It sounds like you're trying to invoke a button via Automation ID. This would be somewhat in the range of things that wouldn't be supported, however, you could loop through all open windows, find the add on window, and then dispatch from that window to invoke a button press in the addon. However, why not just expose some public methods in the add on that could be accessed by your indicator?

    Here's how you can loop through windows:

    Here's how you can loop through windows:

    Code:
    foreach (var window in NinjaTrader.Core.Globals.AllWindows)
    {
    
    }
    Here is an example for finding ChartTraderTIF via automation ID:

    Code:
    else if (State == State.Historical)
    {
    ChartControl.Dispatcher.InvokeAsync(new Action(() => {
    TifSelector tif = Window.GetWindow(ChartControl.OwnerChart).FindFirs t("ChartTraderControlTIFSelector") as TifSelector;
    Print(tif.GtdDate);
    }));
    }
    In your case you'd know the automation ID for the button you're looking for, so once you have the button you would use button.Invoke.

    We wouldn't have any recommendations for third party tools that we'd be able to provide, but I'll leave this open for others to comment on.

    Please let us know if we may be of further assistance to you.



    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks will look into it... It is 3rd party add-on so cannot invoke method directly...

      Can I retrieve object by x:Name instead of Automation ID provided x:Name is unique?

      Also, I know it is unsupported question but should be pretty easy - how to get text from TextBlock object that is displayed on the same add-on?

      Do I need to include any 3rd party libraries into project in order to access these objects manually or are they included by default?

      Looks like here is the link I get get more information from:

      Use UI Automation to find a control matching certain property conditions, create an AutomationElement, get an InvokePattern, and use Invoke on the control.


      Thanks
      Last edited by music_p13; 11-12-2020, 04:07 PM.

      Comment


        #4
        Hello music_p13,

        Thank you for your reply.

        Again, none of this would be documented or officially supported.

        Assuming the third party script has added names or automation IDs you could use either. If you don't have access to the code to find what it is, to find the automation ID's it is suggested to use Microsoft's Inspect tool. My colleague Jesse composed a guide on how to use this tool in the following post:

        http://www.ninjatrader.com/support/f...44&postcount=7

        Getting the text from a TextBlock object would also require finding a name or Automation ID, then reading the the .Text property of the TextBlock.

        If the items you're looking for do not have names or automation IDs, you can technically try to use the visual tree to find controls, but that's pretty complicated and you have to work through a bunch of steps to find it. Here's a publicly available link that may help:



        Here's an example of finding and clicking on a button:

        Hello, I configured my strategy with RealtimeErrorHandling.IgnoreAllErrors. I am handling order rejected in OnOrderUpdate. The problem is that I receive


        If you are wanting to use the Automation methods at the link you provided you would need to add a Using declaration to the top of your script:

        using System.Windows.Automation;

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks a lot!

          Comment


            #6
            Hello again,

            I was able to read title from ChartControl and from ControlCenter, however, I am not able to find the Add-On window... What class should I use in order to access the Add-On window and then its title and its inner objects like TabControl and Button that would be inside the tab control?

            I was using things like:
            Chart chartWindow = Window.GetWindow(ChartControl.Parent) as Chart;
            OR
            ControlCenter cc = NinjaTrader.Core.Globals.AllWindows.First(t => t is ControlCenter) as ControlCenter;

            Then
            if (cc != null)
            {
            cc.Dispatcher.InvokeAsync(() =>
            {

            Print(string.Format("number of windows is:{0}", NinjaTrader.Core.Globals.AllWindows.Count()));

            How can I get the Addon Window? Which class should I use?

            Thanks

            Comment


              #7
              Hello music_p13,

              Thank you for your post.

              Still unsupported, but:

              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(() =>
              {

              You'd need to do this, but look for the AddOn window class instead of NinjaTrader.Gui.Chart.Chart. You would have to know the name of the class for the window to be able to find it. Generally you would need to be able to access the code of the add-on in order to do so.

              Please let us know if we may be of further assistance to you.

              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hello,

                Thanks, I was able to find correct Add-On window.

                I have a following code:

                It finds add-in, prints its title, however, doesn't find the button that I am searching for (I am searching by AutomationID which is also name property in XAML).

                it doesn't get into statement if (closeButton != null)

                Is there something wrong?

                Window also has tab. Should I look for tab first and start searching for button from tab as parent?


                foreach (var window in NinjaTrader.Core.Globals.AllWindows)
                {
                if (!window.GetType().Name.Contains("XYZ Add-in")) continue;
                window.Dispatcher.InvokeAsync(new Action(() =>
                {
                Print(window.Title.ToString());
                System.Windows.Controls.Button closeButton = window.FindFirst("btnClose") as System.Windows.Controls.Button;

                if (closeButton != null)
                {
                System.Windows.Automation.Peers.ButtonAutomationPe er peer = new System.Windows.Automation.Peers.ButtonAutomationPe er(closeButton);
                System.Windows.Automation.Provider.IInvokeProvider invokeProv = peer.GetPattern(System.Windows.Automation.Peers.Pa tternInterface.Invoke) as System.Windows.Automation.Provider.IInvokeProvider ;
                if (invokeProv != null)
                {
                invokeProv.Invoke();
                }
                }
                }));
                }

                Thanks

                Comment


                  #9
                  Hello music_p13,

                  Thank you for your reply.

                  I've attached a pair of example scripts, one being the AddOnFramework which you may already have installed, and then an indicator (TestButtonClick) that demonstrates finding and clicking on a button in that window. You can test this by opening an AddOnFramework window from the New Menu, then applying the indicator to a chart.

                  Please let us know if we may be of further assistance to you.
                  Attached Files
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Excellent! Thanks, that indicator worked against add-in I am using!

                    Comment


                      #11

                      One more follow up for additional control... I know it is unsupported question, but still wonder if you have any tricks/tips...

                      I have another control "TextBlock" - and I need to click on it. I don't know which even is associated with it.

                      Is there any tool that allows to spy and see all events that are implemented/associated with this particular control?

                      I find that object by:
                      System.Windows.Controls.TextBlock myTxt = LogicalTreeHelper.FindLogicalNode((window.Content as DependencyObject), "txtXYZ") as System.Windows.Controls.TextBlock;

                      And then:
                      if (myTxt!= null)
                      {
                      myTxt.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.TextBlock. MouseLeftButtonDownEvent));
                      myTxt.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.TextBlock. MouseLeftButtonUpEvent));
                      }

                      But none of the events triggers click action... I probably have to move mouse over this control and click or something else... Do you have any suggestion I could try to click on textBlock object?

                      Do I really have to get its X/Y coordinates of this control and the to use some win32 mouse click events?

                      Thanks

                      Comment


                        #12
                        Hello music_p13,

                        Thank you for your reply.

                        Inspect can be used to peek around for automation ID's.

                        Raising a button click event on a TextBlock would be more of a WPF related item than a NinjaScript specific item. A publicly available resource that touches on this can be found here:

                        I'm trying to manually fire a MouseLeftButtonDown event on a WPF control programmatically, as I am using the Microsoft Surface SDK, which does not fire MouseLeftButtonDown events, but ContactDown e...


                        I would recommend looking for similar WPF related resources to accomplish tasks like these.

                        You will likely be able to find a solution without having to identify the X Y coordinates of the control.

                        Please let us know if we may be of further assistance to you.
                        Kate W.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by alifarahani, 04-19-2024, 09:40 AM
                        8 responses
                        52 views
                        0 likes
                        Last Post alifarahani  
                        Started by mmckinnm, Today, 01:34 PM
                        2 responses
                        4 views
                        0 likes
                        Last Post mmckinnm  
                        Started by Conceptzx, 10-11-2022, 06:38 AM
                        3 responses
                        60 views
                        0 likes
                        Last Post NinjaTrader_SeanH  
                        Started by f.saeidi, Today, 01:32 PM
                        1 response
                        2 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by traderqz, Today, 12:06 AM
                        9 responses
                        16 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X