I have created a very simple add on. All it does is get a reference to the chart window, and print to the ninjascript output window when events get raised. The addon was created with the ninjascript wizard which put the OnStateChange event in form me. The OnWindowCreated and OnWindowClose events are getting raised, and the OnStateChange event does get raised for some other windows, (You can see if you attached VS debugger with breakpoint) but not the Chart window.
Below is the code for the AddOn to replicate the issue, and I have also attached it as a cs.
Is this a bug?
Regards,
Scott
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.Gui.Tools; #endregion //This namespace holds Add ons in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.AddOns { public class TestOnStateChangeAddOn : NinjaTrader.NinjaScript.AddOnBase { private Chart _chartWindow = null; protected override void OnStateChange() { if (_chartWindow != null) { Print("TestOnStateChangeAddOn.OnStateChange - Event Raised - Chart Window"); } if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Add on here."; Name = "TestOnStateChangeAddOn"; } else if (State == State.Configure) { } } protected override void OnWindowCreated(Window window) { window.Dispatcher.Invoke((Action)(() => { _chartWindow = Window.GetWindow(window) as Chart; if (_chartWindow != null) { Print("TestOnStateChangeAddOn.OnWindowCreated - Event Raised - Chart Window"); } })); } protected override void OnWindowDestroyed(Window window) { if (_chartWindow != null) { Print("TestOnStateChangeAddOn.OnWindowDestroyed - Event Raised - Chart Window"); } } } }
Comment