• 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

  • @tmc_
    replied
    Perfect! Thanks a lot for the help. This thread can be closed.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello @tmc_,

    My mistake, I needed to included that. Post below edited.

    Leave a comment:


  • @tmc_
    replied
    The name 'FindVisualChildren' does not exist in the current context. Am I missing a reference?

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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, 09:26 AM.

    Leave a comment:


  • @tmc_
    replied
    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?

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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

    Leave a comment:


  • @tmc_
    replied
    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, 07:07 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • @tmc_
    replied
    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.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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, 06:51 AM.

    Leave a comment:


  • @tmc_
    replied
    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

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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

    Leave a comment:


  • @tmc_
    replied
    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

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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

    Leave a comment:


  • @tmc_
    started a topic [ChartStyle] Submode icons

    [ChartStyle] Submode icons

    Hi,

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

Latest Posts

Collapse

Topics Statistics Last Post
Started by priceisking, Today, 05:33 PM
0 responses
2 views
0 likes
Last Post priceisking  
Started by vivekniwas, Today, 02:15 PM
1 response
14 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by fibbee, Today, 02:06 PM
1 response
11 views
0 likes
Last Post NinjaTrader_Tyler  
Started by Spaggetti Ninjja, Today, 01:23 PM
1 response
9 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by rexsole, Today, 12:34 PM
1 response
7 views
0 likes
Last Post NinjaTrader_PatrickG  
Working...
X