Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Setting the MenuItem Style of a Menu

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

    Setting the MenuItem Style of a Menu

    Hello,

    This may be a C# question rather than an NT8 question. The indicator adds custom buttons to NT's main navigation menu. I would like to have the option to collapse multiple buttons into one drop menu. By using Controls.Menu and Controls.MenuItem, a drop-down menu was successfully created. https://i.imgur.com/Sqf2CNn.png

    The problem is that it looks bad. To make it look good, copying NT's menu style will make the custom button uniform with the rest of NT's UI. https://i.imgur.com/P1FpTBK.png

    The current solution is to grab one of the menus then grab its style and set my custom menu to it. I tried setting itemHelp to style but that just crashes the indicator.

    Code:
    List<Object> menuObjects = chartWindow.MainMenu.ToList();
    System.Windows.Controls.Menu menuNT = (System.Windows.Controls.Menu) menuObjects[2]; //this grabs the Chart Style menu
    
    Style style = menuNT.Style;
    menu = new System.Windows.Controls.Menu();
    
    menu.Style = style;
    
    System.Windows.Controls.MenuItem itemHelp = new System.Windows.Controls.MenuItem();
    itemHelp.Header = "Buttons";
    
    menu.ItemContainerStyle = menuNT.ItemContainerStyle;
    Alternatively, I should be using Application.Current.TryFindResource("AutomationID" ) method to set values. However, I cannot find the corresponding keys in the BluePrint.xaml. Perhaps NT is not even using Controls.MenuItem to populate a Controls.Menu, but it sure looks like it.

    Edit: Turns out there's no need to create and add a button direclty, just make and add a MenuItem and suscibe an event listner on it.
    One more problem, clicking a button in the drop-down menu only works if the button is clicked not space around the button. Again, this may be more of a C# question. The problem is that every example I find is on Windows.Forms NOT Windows.Controls.

    Thanks
    Last edited by Unsuitable; 10-24-2020, 08:57 PM.
    Unsuitable
    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

    #2
    Hello Unsuitable,

    For menu colors and style I have been using
    Code:
    Application.Current.TryFindResource("MainMenuItem") as Style
    I've uploaded an updated sample found with the link below.
    Hello All, Moving forward this will be maintained in the help guide reference samples and no longer maintained on the forum. Creating Chart WPF (UI) Modifications from an Indicator - https://ninjatrader.com/support/help...ui)-modifi.htm (https://ninjatrader.com/support/helpGuides/nt8/creating-chart-wpf-(ui)-modifi.htm) I've
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB,

      I did note that you use that and I tried setting my menuItem's style to the "MainMenuItem" and that just crashes the indicator. This is what I got so far with setting the
      itemHelp's menuItem background to black (for now) and implementing the edit. https://i.imgur.com/uJxrRqN.png

      I believe it's the Menu itself that needs to be set or changed. I tried looking for what property would contain the background properties, I thought the .ItemContainerStyle would do it but that appears to do nothing,
      Unsuitable
      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

      Comment


        #4
        Hello ChelseaB,

        I took a look at the new sample file and noticed you are using DropMenu, which is probably what I should be using as my method looks clunky at takes a lot of space for not much text.
        Unsuitable
        NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

        Comment


          #5
          Hello Unsuitable,

          A crash may be due to a null object.

          Try copying the code for the style object from my working example script and then check to see if it is null.

          Or let us see the error and trace the error back.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello Unsuitable,

            DropMenu is a custom class declared near the bottom I made just for this example. It has some inheritance which allows me to use that as a template for all new menus.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello ChelseaB,

              I spotted the ntTopBar code snippet that adds menu to the top bar exactly as I did. So no need for that drop-down class, it looked complicated. Looked through it and yes I'm setting the same values. Have a look at my code, perhaps there's something I'm missing.

              Code:
              menu = new System.Windows.Controls.Menu();
              
              Style systemMenuStyle = Application.Current.TryFindResource("SystemMenuStyle") as Style;
              Style mainMenuItemStyle = Application.Current.TryFindResource("MainMenuItem" ) as Style;
              
              menu.Style = systemMenuStyle;
              menu.FontWeight = FontWeights.Regular;
              
              System.Windows.Controls.MenuItem itemHelp = new System.Windows.Controls.MenuItem();
              itemHelp.Header = "Buttons";
              
              menu.Items.Add(itemHelp);
              
              itemHelp.Style = mainMenuItemStyle;
              Unsuitable
              NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

              Comment


                #8
                Hello Unsuitable,

                From this I am not seeing what would cause a null object.

                Are there errors in the log tab of the Control Center?
                What do these errors say?

                Add prints below each action line. Which print is the last print to appear before the error?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ChelseaB,

                  I checked the control center's log and there are no errors pertaining to the indicator.

                  I verified when the error is happening, it's the moment I set the menuItems' style. https://i.imgur.com/oDZXqYL.png
                  Went ahead and printed the mainMenuItemStyle and it returns a System.Windows.Style so it's not like the object is null or anything. Imma try to set the style out of the scope and define them as class variables. (My wording could be off here, have the style variables as you have them in the example).
                  Unsuitable
                  NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                  Comment


                    #10
                    Also, where do you set instrumentMenuSimpleStyle? I see that it's declared, but LoadBrushesFromSkin() does not set it.
                    Unsuitable
                    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                    Comment


                      #11
                      Well... this is why could never program as a career. Turns out I was using System.Windows.Controls.MenuItem instead of NinjaTrader.Gui.Tools.NTMenuItem. *@$#!

                      :P
                      Unsuitable
                      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                      Comment


                        #12
                        Hello Unsuitable,

                        What did you mean by the indicator is crashing?

                        There are no errors in the Log?

                        The indicator is not able to Print(Time[0]); at the top of OnBarUpdate outside of all conditions as new bars are forming?

                        I had some intention of getting the style of the instrument menu but there isn't actually a style specific for the instrument selector. I'll remove this to remove confusion.

                        The Instrument selector is using the 'Colors for menus / drop downs throughout the application' like SubMenuBackground, MenuBorderBrush, MenuSeparator, etc.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello ChelseaB,

                          Originally posted by NinjaTrader_ChelseaB View Post
                          What did you mean by the indicator is crashing?
                          When setting the style of the menuItem, the indicator would not load. No errors in the log were created nor in the output panel (it would print stuff up intill setting the style). Turns out I was using Controls.MenuItem instead of Tools.NTMenuItem so I'm assuming the styles are not compatible thus crashing the indicator. User error code ID-10T haha.
                          Last edited by Unsuitable; 10-26-2020, 04:51 PM.
                          Unsuitable
                          NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                          Comment


                            #14
                            Hello ChelseaB,

                            I noticed that hovering over a menuItem makes the selection blue and not grey (in line with the skin). Would that data be contained in instrumentMenuSimpleStyle?

                            Click image for larger version

Name:	4RuAExi.png
Views:	560
Size:	2.8 KB
ID:	1125215
                            vs

                            Click image for larger version

Name:	5z2ExFr.png
Views:	547
Size:	12.3 KB
ID:	1125218

                            Thanks
                            Attached Files
                            Unsuitable
                            NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                            Comment


                              #15
                              Hello Unsuitable,

                              instrumentMenuSimpleStyle doesn't exist. There is no instrument menu style.

                              The instrument menu is using the brushes in the skin in the section 'Colors for menus / drop downs throughout the application' like SubMenuBackground, MenuBorderBrush, MenuSeparator, etc.
                              You may be wanting MenuHilightBorderBrush or MenuHilightBackgroundBrush.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X