OnWindowDestroyed()

View as Markdown

Definition

This method is called whenever a new NTWindow is destroyed. It will be called in the thread of that window. A window is destroyed either by the user closing the window, closing a workspace, or on a shut down of NinjaTrader.

This method will also be called on a recompile of the NinjaTrader.Custom project (e.g., when you compile an indicator, strategy, or add-on)

Method Return Value

This method does not return a value.

Syntax

OnWindowDestroyed(Window window)

Parameters

ParameterDescription
windowA Window object which is being removed from the workspace

Examples

1public class MyWindowAddOn : AddOnBase
2{
3 private NTMenuItem myMenuItem;
4 private NTMenuItem existingMenuItem;
5
6 protected override void OnStateChange()
7 {
8 if (State == State.SetDefaults)
9 {
10 Description = "Our custom MyWindow add on";
11 Name = "MyWindow";
12 }
13 }
14
15 // Will be called as a new NTWindow is destroyed. It will be called in the thread of that window
16 protected override void OnWindowDestroyed(Window window)
17 {
18 if (myMenuItem != null && window is ControlCenter)
19 {
20 if (existingMenuItem != null && existingMenuItem.Items.Contains(myMenuItem))
21 existingMenuItem.Items.Remove(myMenuItem);
22
23 myMenuItem.Click -= OnMenuItemClick;
24 myMenuItem = null;
25 }
26 }
27}