public class MyWindowAddOn : AddOnBase
{
private NTMenuItem myMenuItem;
private NTMenuItem existingMenuItem;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Our custom MyWindow add on";
Name = "MyWindow";
}
}
// Will be called as a new NTWindow is created. It will be called in the thread of that window
protected override void OnWindowCreated(Window window)
{
// We want to place our add on in the Control Center's menus
ControlCenter cc = window as ControlCenter;
if (cc == null)
return;
/* Determine we want to place our add on in the Control Center's "New" menu
Other menus can be accessed via the control's Automation ID. For example: toolsMenuItem,
workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
existingMenuItem = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
if (existingMenuItem == null)
return;
// 'Header' sets the name of our add on seen in the menu structure
myMenuItem = new NTMenuItem { Header = "My Menu Item",
Style = Application.Current.TryFindResource("MainMenuItem") as Style };
// Place our add on into the "New" menu
existingMenuItem.Items.Add(myMenuItem);
// Subscribe to the event for when the user presses our add on's menu item
myMenuItem.Click += OnMenuItemClick;
}
// Open our add on's window when the menu item is clicked on
private void OnMenuItemClick(object sender, RoutedEventArgs e)
{
// Show the NTWindow "MyWindow"
Core.Globals.RandomDispatcher.InvokeAsync(new Action(() => new MyWindow().Show()));
}
}