• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

[ChartStyle] Submode icons

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

    [ChartStyle] Submode icons

    Hi,

    Is it possible to set icons for submodes of a chart style? How do I do that?


    #2
    Hello @tmc_,

    Yes, Gui.Tools.NTMenuItem objects have an Icon property (the type is object) that can be set to geometry, string, or image.

    Below is a public link to the microsoft documentation.
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    And a link to an example that sets an Icon property of an NTMenyItem.
    https://ninjatrader.com/support/foru...275#post536275
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the reply. How do I access this NTMenuItem object generated when overriding SubModes? See the attachment for a sample chart style. I would like to show the icons in submenu next to the modes.

      Attached Files

      Comment


        #4
        Hello @tmc_,

        I would recommend creating an a NTMenuItem object the same way the example I have provided you demonstrates.

        Below is a public link to the help guide on NTMenuItem.
        https://ninjatrader.com/support/help...ntmenuitem.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I ended up changing the NTMenuItem icons in overridden OnRender method. However, this leads to late icon rendering, I would like to see the icons before the ChartStyle is applied. Is it possible to access ChartControl before the OnRender? Keep in mind we are talking about ChartStyle and not an Indicator.

          You can find the current solution in the attachment below.
          Attached Files

          Comment


            #6
            Hello @tmc_,

            WPF elements should not be added in OnRender.

            (edited. the example adds the controls from State.Historical instead of State.DataLoaded but really either works)
            In the example I have provided you this adds the controls in a Dispatch.InvokeAsync() run from OnStateChange when state is State.Historical.
            Last edited by NinjaTrader_ChelseaB; 07-30-2018, 07:51 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I am not adding WPF elements, just changing icons if it wasn't done yet. I know it should not be done in OnRender, that's why I have asked how to access ChartControl inside of ChartType before OnRender method. It seems to be not accessible in OnStateChange and therefore I can't use the solution you have provided.

              Comment


                #8
                Hello @tmc_,

                NTMenuItem is a WPF element. To confirm you are not creating or adding this in OnRender(), correct?

                ChartControl can be accessed in any method after the State is State.Configure.

                May I confirm you have reviewed the example I have provided you?
                Please take a look at State.Historical in this example.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Yes, correct. You can see the code in the attachment or here. I can access the class but not the object, it's under IndicatorRenderBase but I want to access it from ChartStyle. Or am I doing something wrong?
                  Last edited by @tmc_; 07-30-2018, 08:07 AM.

                  Comment


                    #10
                    Hello @tmc_,

                    Have you linked the wrong file?

                    Attached is a screenshot of what I am seeing from what you have linked.

                    This file is showing that WPF elements are being added in OnRender() which I have advised against.

                    My example demonstrates adding WPF from OnStateChange when State is State.Historical.

                    I think you have accidentally linked the wrong file. Can you link the file that adds the elements from OnStateChange that you have mentioned?
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      This is the right file. I said I can access only ChartControl class in OnStateChange(), I am working with ChartStyle, not an Indicator and the ChartControl object is under IndicatorRenderBase. That's why I worked around it by using OnRender() which passes the ChartControl object as an argument. How do I access ChartControl object in OnStateChange() of ChartStyle?

                      Comment


                        #12
                        Hello @tmc_,

                        I'm understanding your inquiry now.
                        The ChartStyle scripts don't have have a ChartControl object available to the entire script.

                        For addon type scripts like custom bar types, chart styles, custom addon windows, you would need to loop through the windows, find the window and get the ChartControl object.
                        Code:
                        protected override void OnStateChange()
                        {
                        	if (State == State.Configure)
                        	{
                        		NTWindow ntWindow;
                        
                        		foreach (Window window in NinjaTrader.Core.Globals.AllWindows)
                        		{
                        			ntWindow = (NTWindow)window;
                        
                        			window.Dispatcher.Invoke(new Action(() =>
                        			{
                        				if (ntWindow.Caption.Contains("Chart"))
                        					foreach (ChartControl cc in FindVisualChildren<ChartControl>(ntWindow))
                        						foreach (object obj in cc.ChartObjects)
                        							if (obj.GetType() == typeof(ChartBars))
                        								if ((obj as ChartBars).Properties.ChartStyle == this)
                        									thisChartControl = cc;
                        			}));
                        
                        			if (thisChartControl != null)
                        			{
                        				// you've got a ChartControl you can do whatever you want with now		
                        			}
                        		}
                        	}
                        }
                        
                        public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
                        {
                        	if (depObj != null)
                        	{
                        		for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                        		{
                        			DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                        			if (child != null && child is T)
                        				yield return (T)child;
                        
                        			foreach (T childOfChild in FindVisualChildren<T>(child))
                        				yield return childOfChild;
                        		}
                        	}
                        }
                        Last edited by NinjaTrader_ChelseaB; 07-30-2018, 10:26 AM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          The name 'FindVisualChildren' does not exist in the current context. Am I missing a reference?

                          Comment


                            #14
                            Hello @tmc_,

                            My mistake, I needed to included that. Post below edited.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Perfect! Thanks a lot for the help. This thread can be closed.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by aligator, Today, 12:29 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post aligator  
                              Started by bob77713, Today, 11:30 AM
                              0 responses
                              0 views
                              0 likes
                              Last Post bob77713  
                              Started by FMtrader, 03-15-2019, 02:30 AM
                              6 responses
                              38 views
                              0 likes
                              Last Post James108  
                              Started by timko, Today, 08:18 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post timko
                              by timko
                               
                              Started by victorsmith, Today, 06:00 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post victorsmith  
                              Working...
                              X