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

Getting skin properties

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

    Getting skin properties

    Hi,

    How does one get the properties of the skin in use? Specifically, I'm trying to get the color of the main menu icons. I can call ChartControl.Properties.ChartText.GetHashCode() to get the ChartControl color, but looking for the skin's text color.

    Thanks
    Unsuitable
    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

    #2
    Hello Unsuitable,

    Below is a link to a forum post on getting values from the skin.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea B,

      I saw that post before making this one and it doesn't exactly solve the problem. I don't know what resource to search for. Orignially I thought I could get the button as a resource. So I went ahead and printed the list of avaible objects in chartWindow.MainMenu. Got the last object which happend to be a button and that was given the name "miProperties". No dice, althoguht this is probably not the right thing to do or call.

      Code:
      SolidColorBrush someBrush = Application.Current.TryFindResource("miProperties") as SolidColorBrush;
      Here's a work around but this doesn't use the Application.Current.TryFindResource() but directly gets color info from a button:

      Code:
      foreach (Object btn in chartWindow.MainMenu)
      {
        Print(btn.ToString());
      }
      
      System.Windows.Controls.Button iconButton = (System.Windows.Controls.Button) chartWindow.MainMenu.Last();
      Print(iconButton.Name);
      
      //System.Windows.Controls.Button miPropertiesButton = Application.Current.TryFindResource("miProperties" ) as System.Windows.Controls.Button;
      
      Print(iconButton.Foreground + " color");
      See ColorOutput.png for what this code outputs. (the pic is reddish cause of f.lux)

      Click image for larger version

Name:	ColorOutput.png
Views:	588
Size:	9.1 KB
ID:	1122031

      The problem with my method is that it's assuming A LOT of conditions. It's assuming the order in which objects are added to chartWindow.MainMenu. Application.Current.TryFindResource() is probably the right way to do it. Any help?

      Thanks
      Unsuitable
      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

      Comment


        #4
        Decided to clean up my method. It checks that the last object is a button... but again it assumes that it will be a button and that NT8 adds the MainMenu buttons properly.

        Code:
        SolidColorBrush buttonBrush = (SolidColorBrush) new BrushConverter().ConvertFromString("#e6e6e6"); //this would be the default color
        Object objectToGrabColor = chartWindow.MainMenu.Last();
        
        if (objectToGrabColor is System.Windows.Controls.Button)
        {
          System.Windows.Controls.Button buttonToGrabColor = (System.Windows.Controls.Button) objectToGrabColor;
          buttonBrush = (SolidColorBrush) new BrushConverter().ConvertFromString(buttonToGrabCol or.Foreground.ToString());
        }
        Unsuitable
        NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

        Comment


          #5
          Hello Unsuitable,

          Once you have the AutomationID of the control or object we should be able to find this in the skin, as the resources in the skin use those AutomationIDs.

          MS Inspect can be used to find AutomationIDs.
          A better link to a post from jesse about AutomationIDs can be found here.


          Another approach is using a color picker program to extract the hex code of the brush of the control or object, and then to search through the XAML files to see where it is used.

          Below are a few publicly available links to 3rd party applications found through a google search.
          Color Cop is a free multi-purpose color picker for Microsoft Windows


          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi ChelseaB,

            I sudo understand what you mean. The thing with the AutomationIDs is that I have to download the Windows SDK which I don't have the data for at the moment. I've found the XAML files of the skin, it wasn't that hard to find the color. The thing about hard setting the color is that a certain color may not be properly visible when using another skin. For example, going from a dark skin to a light skin.

            The solution I came up with does work when switching skins. Again that assumes the order of buttons and that they are added in the first. Is it a guarantee that NT will create main menu elements in the same way each time? I don't know. If some is able to find the automationID that corresponds to one of the main menu elements that would awesome!

            Nevertheless, thank you ChelseaB for helping out the past few weeks! Your help has and will go a long way.

            Thanks
            Last edited by Unsuitable; 10-11-2020, 07:33 PM.
            Unsuitable
            NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

            Comment


              #7
              Hello Unsuitable,

              I'm not sure I understand.

              The AutomationIDs for NinjaTrader resources defined in the core should be the same no matter what the skin. Using a different name I don't think would pull up anything..

              Code in a method in the same thread is run from top to bottom. It would depend on if the code is in the same method and same thread.

              If UI changes are made in different methods with Dispatcher.InvokeAsync(), then there is no guarantee to the order of events as they have to invoke into another thread.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi ChelseaB,

                Originally posted by NinjaTrader_ChelseaB View Post
                The AutomationIDs for NinjaTrader resources defined in the core should be the same no matter what the skin. Using a different name I don't think would pull up anything..
                Not talking about AutomationIDs, that would remain the same. When asking if the main menu objects will be added the same way every time, I was referring to my solution in which it gets the actual object.

                Code:
                SolidColorBrush buttonBrush = (SolidColorBrush) new BrushConverter().ConvertFromString("#e6e6e6"); //this would be the default color
                Object objectToGrabColor = chartWindow.MainMenu.Last();
                
                if (objectToGrabColor is System.Windows.Controls.Button)
                {
                  System.Windows.Controls.Button buttonToGrabColor = (System.Windows.Controls.Button) objectToGrabColor;
                  buttonBrush = (SolidColorBrush) new BrushConverter().ConvertFromString(buttonToGrabCol or.Foreground.ToString());
                }
                Thanks
                Last edited by Unsuitable; 10-12-2020, 09:52 AM. Reason: Typo
                Unsuitable
                NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                Comment


                  #9
                  Hello Unsuitable,

                  This would not be using a color from the skin as I was suggesting from linking Jesse's post on using AutomationIds.

                  This would be using a hard coded colors you have decided on yourself, and are not coming from the skin.

                  Using AutomationIds found from MSInspect (or by using the AutomationID found in the skin by searching for the color hex), this returns the resource from the skin (which is a resource dictionary). The resource might be a brush, or a gradient, or a style..

                  Application.Current.FindResource("BasicEntryButton ") as Style // <--- BasicEntryButton is an AutomationId for the style in the skin for buttons on the Atm
                  Application.Current.TryFindResource("FontButtonBru sh") as SolidColorBrush ?? new SolidColorBrush(Brushes.Black.Color); // <-- FontButtonBrush would be the AutomationId for button font brush




                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi ChelseaB,

                    I believe we are miss understanding each other. The method to retrieve colors by the automation ID will give colors based on whatever skin is loaded (from my understanding). When I said "AutomationIDs, that would remain the same" I was referring to the actual name of the resource, not the color. The color would depend on the skin... Again I may be mistaken how the solution you're providing me works, which I cannot try out due to having a low data cap. The Windows SDK is about 600 MB and I cannot download the individual tool to find the proper AutomationID.

                    When I asked would the manner in which NT8 loads in the buttons for the main menu elements remain consistent, I was strictly referring to my method of getting the skin's color. At the moment, my method gets the list that the main menu objects are located. Then I grab the last element in that list, which happens to be a button. Which I can refer to the buttons foreground property, this has the color for the skin. When I refer to the color for skin, I'm referring to the button's icon color... which is based on the skin that the user has selected. This color is selected based on visibility in relation to the chart color.

                    Click image for larger version

Name:	l7BTfPz.png
Views:	560
Size:	46.0 KB
ID:	1122312
                    Unsuitable
                    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                    Comment


                      #11
                      Hello Unsuitable,

                      The name of the resource is the AutomationID and should not change in different skins. This should be the same.

                      The ColorDisabledBorder in the Dark skin BluePrint.xml file uses the same AutomationID as the resource in the Light skin BluePrint.xml file. They have a different color hex value, but they are using the same AutomationID.

                      I am not understanding what is not consistent. The AutomationID (or resource name) should be consistently the same in all skins for NinjaTrader controls.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello ChelseaB,

                        I understand. In order to get the proper automationID I have to install the Windows SDK, which I cannot.

                        My solution works for now... all that I'm wondering is if my solution will work no matter. My solution depends on the order the objects are addded in the chartWindow.MainMenu (in the photo I wrote chartControl.MainMenu). The order would not matter if all the objects in the chartWindow.MainMenu list were buttons. See post #3 for the objects within the chartWindow.MainMenu list.

                        Anyways, when I'm able to get the automationID I will use that method instead. For now, my soltuion is questionable. This isn't really a question if my code works, cause it does work. Again it's dependant on how the NT code is written and how it builds the a chart window, this is proabbly out of the scope of the indicator developement forums.
                        Unsuitable
                        NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                        Comment


                          #13
                          Hello Unsuitable,

                          Because other indicators can change things, hard coding or getting values from existing controls is not guaranteed to match the skin. But it would match what you hard coded or what that control had..

                          Are you having a specific issue with this that we can dig in to?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello ChelseaB,

                            No, for now it's "solved" until I have an AutomationID that is assigned one of the NT's main menu buttons.
                            Unsuitable
                            NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                            Comment


                              #15
                              Hello Unsuitable,

                              What are you considering the menu buttons?
                              Do you mean the menu items in the New menu?
                              Try
                              Code:
                              Style mainMenuItemStyle            = Application.Current.TryFindResource("MainMenuItem") as Style;
                              Then apply the style to the menu item in your menu.

                              For buttons specifically there is FontButtonBrush and ButtonBackgroundBrush.
                              Code:
                              controlFontBrush = Application.Current.TryFindResource("FontButtonBrush") as SolidColorBrush ?? new SolidColorBrush(Brushes.White.Color);
                              controlBackgroundBrush = Application.Current.TryFindResource("ButtonBackgroundBrush") as LinearGradientBrush ?? new LinearGradientBrush(Colors.White, Colors.Black, 1);
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by MartinT, 05-17-2023, 06:00 AM
                              18 responses
                              172 views
                              0 likes
                              Last Post flybuzz
                              by flybuzz
                               
                              Started by sgordet, Today, 05:24 AM
                              2 responses
                              20 views
                              0 likes
                              Last Post sgordet
                              by sgordet
                               
                              Started by Board game geek, Today, 02:20 AM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by ZeroKuhl, Yesterday, 04:31 PM
                              3 responses
                              24 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by knighty6508, Today, 01:20 AM
                              3 responses
                              21 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Working...
                              X