Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create a menu strip in main form via a custom Addon

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Create a menu strip in main form via a custom Addon

    Dear everyone,

    for some indicators and individual trading forms, I would like to create some general settings menus.
    This menus I would like to link in the main form as menu strips. I've seen in some custom addons, that this is possible.
    Do you have or can link an example how to do this?

    Click image for larger version

Name:	2021-03-21 12_37_08-Window.png
Views:	491
Size:	54.1 KB
ID:	1147625

    Additionally is it also possible to create some individual Chart --> Properties?

    Click image for larger version

Name:	2021-03-21 12_49_25-Window.png
Views:	397
Size:	53.7 KB
ID:	1147626

    Thanks in advance.
    Airwave
    NinjaTrader Ecosystem Vendor - Airwave

    #2
    Hello Airwave,

    Thanks for your post.

    For the toolbar I would suggest looking at my colleague Chelsea's examples here: https://ninjatrader.com/support/foru...considerations

    You would not be able to add to the existing properties but could use a form window. Please see this thread for example/references: https://ninjatrader.com/support/foru...m-in-indicator

    Comment


      #3
      Hello,

      thanks for your help.

      Now I'm trying to add this menu item using following code:




      HTML Code:
       protected override void OnWindowCreated(Window window)
      {
      
      // We want to place our AddOn in the Control Center's menus
      ControlCenter cc = window as ControlCenter;
      if (cc == null)
      return;
      //BarsPropertiesPropertyGridEditorIsStableSession
      
      /* Determine we want to place our AddOn in the Control Center's "New" menu
      Other menus can be accessed via the control's "Automation ID". For example: toolsMenuItem, workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
      existingMenuItemInControlCenter = cc.FindFirst("PART_Menu") as NTMenuItem;
      if (existingMenuItemInControlCenter == null)
      return;
      
      // 'Header' sets the name of our AddOn seen in the menu structure
      addOnFrameworkMenuItem = new NTMenuItem() { Header = "AddOn Framework", Style = Application.Current.TryFindResource("MainMenuItem" ) as Style };
      
      // Add our AddOn into the "New" menu
      existingMenuItemInControlCenter.Items.Add(addOnFra meworkMenuItem);
      
      // Subscribe to the event for when the user presses our AddOn's menu item
      //addOnFrameworkMenuItem.Click += OnMenuItemClick;
      }

      Unfortunetely cc.FindFirst("PART_Menu") is always null even with inspect.exe this is the correct automationid.
      cc is found!

      Could you give me a hint, what I'm doing wrong here?

      Thanks in advance
      Airwave
      NinjaTrader Ecosystem Vendor - Airwave

      Comment


        #4
        Hello,

        I'm a little further now, but now I'm getting an exception:

        HTML Code:
        protected override void OnWindowCreated(Window window)
        {
        
        ControlCenter cc = window as ControlCenter;
        if (cc == null)
        return;
        
        var existingMenuItemInControlCenter = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
        
        if (existingMenuItemInControlCenter == null)
        return;
        
        var menuStack= VisualTreeHelper.GetParent(existingMenuItemInControlCenter) as StackPanel;
        
        var addOnFrameworkMenuItem = new NTMenuItem();
        addOnFrameworkMenuItem.Header = "TEST";
        
        try
        {
             menuStack.Children.Add(addOnFrameworkMenuItem);
        }
        catch (Exception e)
        {
                throw;
        }
        
        }
        So this is throwing: Cannot explicitly modify Children collection of Panel used as ItemsPanel for ItemsControl. ItemsControl generates child elements for Panel.

        Could you guide me here?

        Thanks in advance.


        Airwave
        NinjaTrader Ecosystem Vendor - Airwave

        Comment


          #5
          Hello Airwave,

          Thanks for your reply.

          I posted a reply to you yesterday and it looks like it did not get posted as I don't see it.

          You will want to add your menu like this in OnWindowCreated: controlCenter.MainMenu.Add(newMenuItem);

          ChartToolBarCustomMenuExample can be referenced to build on that and add your own menu.

          The code in ChartToolBarCustomMenuExample that sets an automation ID and checks for the automation ID would be used to prevent multiple buttons from being added when we compile for example.


          Comment


            #6
            Great, thanks a lot, that did the trick.
            One last question. I only want an image as button, so I used:

            HTML Code:
            imageStream=<cut>
            BitmapFrame bmp = BitmapFrame.Create(imageStream);
            
            ImageBrush ib = new ImageBrush();
            ib.ImageSource = bmp;
            
            addOnFrameworkMenuItem.Background = ib;
            
            Style s = new Style();
            s.TargetType = typeof(System.Windows.Controls.MenuItem);
            s.Setters.Add(new Setter(System.Windows.Controls.MenuItem.FontSizePr operty, 11.0));
            s.Setters.Add(new Setter(System.Windows.Controls.MenuItem.Background Property, Brushes.Orange));
            s.Setters.Add(new Setter(System.Windows.Controls.MenuItem.Foreground Property, Brushes.Black));
            s.Setters.Add(new Setter(System.Windows.Controls.MenuItem.FontFamily Property, new FontFamily("Arial")));
            s.Setters.Add(new Setter(System.Windows.Controls.MenuItem.FontWeight Property, FontWeights.Bold));
            Trigger t2 = new Trigger();
            t2.Property = System.Windows.Controls.MenuItem.IsMouseOverProper ty;
            t2.Value = true;
            t2.Setters.Add(new Setter(Control.BackgroundProperty, System.Windows.Media.Brushes.Violet));
            s.Triggers.Add(t2);
            
            addOnFrameworkMenuItem.Style = s;
            
            cc.MainMenu.Add(addOnFrameworkMenuItem);
            I experimented a bit with the style because, when I'm in Mouse Over position, the image disappears.
            When I'm using default
            (addOnFrameworkMenuItem.Style = Application.Current.TryFindResource("MainMenuItem" ) as Style
            ,the entire image not been displayed.

            Click image for larger version  Name:	2021-03-30 21_56_02-Control Center - Accounts.png Views:	0 Size:	3.6 KB ID:	1149263

            Could you help me with the style to on the one hand use the ninja style but also show the image?

            Thank you so much.
            Last edited by Airwave; 03-30-2021, 02:02 PM.
            Airwave
            NinjaTrader Ecosystem Vendor - Airwave

            Comment


              #7
              Hi,

              it was just as easy to put the image into .header :-)

              So it's working now. Maybe you can help me with the style to get it Ninjatrader aligned.


              When I use

              addOnFrameworkMenuItem.Style = Application.Current.TryFindResource("MainMenuItem" ) as Style;

              I have problems, that the image disappears on first click on the menuitem:

              Click image for larger version

Name:	2021-03-31 11_15_36-Window.png
Views:	357
Size:	7.6 KB
ID:	1149365

              Click image for larger version  Name:	2021-03-31 11_12_28-Window.png Views:	0 Size:	5.8 KB ID:	1149363
              Click image for larger version  Name:	2021-03-31 11_12_35-Window.png Views:	0 Size:	3.8 KB ID:	1149364


              But when I use an own style the design is not Ninjatrader aligned:


              Click image for larger version  Name:	2021-03-31 11_08_55-Window.png Views:	0 Size:	9.3 KB ID:	1149362

              Style s = new Style();
              s.TargetType = typeof(System.Windows.Controls.MenuItem);
              s.Setters.Add(new Setter(System.Windows.Controls.MenuItem.Foreground Property, Brushes.Black));
              Trigger t2 = new Trigger();
              t2.Property = System.Windows.Controls.MenuItem.IsMouseOverProper ty;
              t2.Value = true;
              s.Triggers.Add(t2);


              Could you help me how to get this done?

              Thanks
              Airwave
              NinjaTrader Ecosystem Vendor - Airwave

              Comment


                #8
                Hello Airwave,

                This is Jim responding on behalf of Paul who is out of the office at this time.

                Paul and I have set up some tests similar to what you are doing and I can share I am getting the same results as you are when testing an image for the header part of a menu item that is stylized with our internal styles. These internal menu item styles were not designed to support using an image for the Header part, so they do break when using an image for the Header of a NinjaTrader stylized MenuItem.

                Our styles will work nicely if you assign an Image Control to the Icon part of the MenuItem, and this would be our recommendation.

                Using an image for the Header part may work in your case if a completely custom style is written, but we could not assist with helping to create a custom style since all of the styling is internal to the platform. Our Scripting Support team does not have access to internal source code/internal styles and this would not be something that we could help with.

                I have attached a modification to our minimal AddOnShell example to demonstrate where this works nicely when used as an Icon, for your reference and for the thread's reference.

                As a side note, I am noticing that a crash will occur if importing a second time because the Control Center is already using the image. I have brought the matter to our Quality Assurance team's attention. Paul or I will follow up with you as this develops.

                We look forward to assisting.
                Attached Files

                Comment


                  #9
                  Hello Jim,

                  thanks a lot. Problem with the icon is of course, that this is not drawn on the entire button :-) .

                  So I guess its not possible to put the ninja style in a variable and just change the image blocking / disappearing attributes and then attach the style to the "new menuitem"?

                  Like
                  Style s = application.Current.TryFindResource("MainMenuItem" ) as Style;

                  s.changeTheImageDisappearingAttribute=xyz

                  mynewmenuitem.Style = s;

                  Thanks in advance.
                  Airwave
                  NinjaTrader Ecosystem Vendor - Airwave

                  Comment


                    #10
                    Hello Airwave,

                    Thanks for your reply.

                    Correct, there is not a quick change to make to the style to get it working with image headers.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    558 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    324 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    545 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    547 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X