OnWindowCreated()

View as Markdown

Definition

This method is called whenever a new NTWindow is created. It will be called in the thread of that window. This is where you would install your AddOn to an existing window, or if creating your own custom window, add a Menu item to the NinjaTrader Control Center.

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

OnWindowCreated(Window window)

Parameters

ParameterDescription
windowA Window object which is being added to 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 created. It will be called in the thread of that window
16 protected override void OnWindowCreated(Window window)
17 {
18 // We want to place our add on in the Control Center's menus
19 ControlCenter cc = window as ControlCenter;
20 if (cc == null)
21 return;
22
23 /* Determine we want to place our add on in the Control Center's "New" menu
24 Other menus can be accessed via the control's Automation ID. For example: toolsMenuItem,
25 workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
26 existingMenuItem = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
27 if (existingMenuItem == null)
28 return;
29
30 // 'Header' sets the name of our add on seen in the menu structure
31 myMenuItem = new NTMenuItem { Header = "My Menu Item",
32 Style = Application.Current.TryFindResource("MainMenuItem") as Style };
33
34 // Place our add on into the "New" menu
35 existingMenuItem.Items.Add(myMenuItem);
36
37 // Subscribe to the event for when the user presses our add on's menu item
38 myMenuItem.Click += OnMenuItemClick;
39 }
40
41 // Open our add on's window when the menu item is clicked on
42 private void OnMenuItemClick(object sender, RoutedEventArgs e)
43 {
44 // Show the NTWindow "MyWindow"
45 Core.Globals.RandomDispatcher.InvokeAsync(new Action(() => new MyWindow().Show()));
46 }
47}