Is it possible to set icons for submodes of a chart style? How do I do that?
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!
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
NinjaTrader
[ChartStyle] Submode icons
Collapse
X
-
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.
And a link to an example that sets an Icon property of an NTMenyItem.
Chelsea B.NinjaTrader Customer Service
-
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
-
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
-
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
-
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
-
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
-
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?Chelsea B.NinjaTrader Customer Service
Comment
-
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
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Critical_Catch, Today, 08:35 AM
|
0 responses
8 views
0 likes
|
Last Post Today, 08:35 AM | ||
Started by smartromain, Today, 02:52 AM
|
0 responses
18 views
0 likes
|
Last Post
by smartromain
Today, 02:52 AM
|
||
Started by Marklhc1988, 04-19-2023, 11:11 AM
|
12 responses
580 views
1 like
|
Last Post
by victor68133
Today, 12:10 AM
|
||
Started by nicthe, Yesterday, 02:58 PM
|
1 response
17 views
0 likes
|
Last Post
by nicthe
Yesterday, 03:23 PM
|
||
Started by percy3687, 05-17-2024, 12:28 AM
|
3 responses
38 views
0 likes
|
Last Post
by percy3687
Yesterday, 02:53 PM
|
Comment