NTMenuItem

View as Markdown

Definition

NTMenuItem is used to create new menu entries. For example, an instance of this class can be placed in an existing Control Center menu to launch an NTWindow as part of an AddOn, as seen in the example code below.

For a complete, working example of this class in use, download the framework example located on our Developing AddOns Overview.

Examples

1private NTMenuItem myNewMenuItem;
2private NTMenuItem existingControlCenterNewMenu;
3
4protected override void OnWindowCreated(Window window)
5{
6 // We want to place the menu item for the AddOn in the Control Center's "New" menu
7 // First obtain a reference to the Control Center window
8 ControlCenter cc = window as ControlCenter;
9 if (cc == null)
10 return;
11
12 /* Determine we want to place the AddOn in the Control Center's "New" menu
13 Other menus can be accessed via the control's "Automation ID". For example: toolsMenuItem, workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
14 existingControlCenterNewMenu = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
15 if (existingControlCenterNewMenu == null)
16 return;
17
18 // Instantiate myNewMenuItem
19 // 'Header' sets the name of our AddOn seen in the menu structure. 'Style' sets the font style.
20 myNewMenuItem = new NTMenuItem { Header = "AddOn Framework", Style = Application.Current.TryFindResource("MainMenuItem") as Style };
21
22 // Add our AddOn menu item into the "New" menu
23 existingControlCenterNewMenu.Items.Add(myNewMenuItem);
24
25 // Subscribe to the event for when the user presses the menu item
26 myNewMenuItem.Click += OnMenuItemClick;
27}