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

How to add a MenuItem to the ContextMenu of an add-on deriving from NTTabpage?

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

    How to add a MenuItem to the ContextMenu of an add-on deriving from NTTabpage?

    To simplify this question, my add-on follows the exact same architecture of the "AddOn Framework" sample but much simpler with only a couple of controls. It works just fine. So if you tell me how it can be done in the AddOnFramework sample, I can take it from there.

    I tried unsuccefully
    Code:
    this.ContextMenu.Items.Add(new NTMenuItem { Header = "My New ContextMenu Item"});
    in the contructor and in several other methods in all of these classes:

    Code:
        AddOnFramework 
        AddOnFrameworkWindowFactory
        AddOnFrameworkWindow
        AddOnFrameworkTab
        TabControlManager helper methods
    Ultimately, one of these classes wraps a ContextMenu object that visually looks like the attached image in which the only menu items are the ones related to managing the tabs.

    Please help.
    Attached Files

    #2
    Hello xcondor,

    Thank you for the post.

    I wanted to check, are you trying to modify the Tab context menu that you have shown specifically or add a Context to a control you have created in the tab?

    If you are trying to append to/edit an existing context menu the platform already offers, you will very likely need to follow the approach laid out here: https://ninjatrader.com/support/foru...87&postcount=6

    If the context in question is generated dynamically, you would need to use the opening event of the context menu to modify the list.

    If this is a control of your own, you should be able to add a context menu to that control. The Control will likely have a Context property which you can assign a new Context menu to and then items. For example:

    Code:
    System.Windows.Controls.Grid myGrid;
    myGrid.ContextMenu = new System.Windows.Controls.ContextMenu();
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      I wanted to check, are you trying to modify the Tab context menu that you have shown specifically or add a Context to a control you have created in the tab?
      This tab menu specifically. I got it now. Thanks!

      On a related topic, the handler I'm hooking into the new menuitem's click event is to launch a dialog window for preferences of my addon. I could develop mt own Properties dialog and a way to persist the settings in an XML file but why reinvent the wheel...

      Is there a a Properties dialog class available? The experience for the user would be much more consistent. The standard 2 columns, expand/collapse grouping etc.

      Thanks

      Comment


        #4
        Hello xcondor,

        Yes, this is also something I have covered previously, you can find a sample at the following link:



        As noted in the other post, that is not a complete sample meaning it will not apply changes to the selected indicator completely and likely will produce an error upon using it. The sample is mainly intended to demonstrate what is required to use a property grid and selecting an object that has properties. In your use case for settings, your settings object that is selected in the property grid would be much less complex than the internal indicators which should remove the error portion of that sample. You would also be able to control the properties of your custom object completely unlike the sample that uses an indicator.

        For saving properties of your objects, you have a few options. You can use standard C# xml serialization, I covered this here: https://ninjatrader.com/support/foru...36&postcount=6

        For add-ons, you can use the persistence interface: https://ninjatrader.com/support/help...acePersistence

        I have attached a sample of using addon persistence for general serialization as it appears I have not yet uploaded this to the forum. The persistence sample simply demonstrates an addon with some text fields. You can enter text and save the workspace, upon loading the workspace the text is restored.


        I look forward to being of further assistance.
        Attached Files
        JesseNinjaTrader Customer Service

        Comment


          #5
          I was able to successfully add a context menu to the NTWindow, but I am unsure how to find and then add a menu item to the generated context menu for the control. The controls I have placed in my NTTabPage have no context menu. By default, the menu from the first post shows up whenever I right click on the contents of my NTTabPage. I am fine with this behavior. I am unable to figure out how to add to this menu.

          I tired adding a handler to NTTabPage and the handler gets called but the NTTabPage doesn't have a context menu assigned. How do I get the context menu that is generated, so I can add my menu item to it?

          Comment


            #6
            Hello ntbone,

            Thanks for your post.

            The ContextMenus would need to be added to a control, either in a grid the houses your controls or on the controls themselves.

            This may be easiest to perform in the XAML of your window. You could try using the following XAML to test adding context menus to your controls.

            I have attached a modification of our AddOnShell example that has context menus added to the main grid and the button that is added. We can note that the Context menu is not opening outside of the grid.

            Publicly available information on creating ContextMenus in WPF windows can be found below.



            We look forward to assisting.
            Attached Files
            JimNinjaTrader Customer Service

            Comment


              #7
              I want to add an entry to the generated menu as shown in the screen shot above. I want all the commands, as show above to still appear in the menu, and then add my items to the menu. When I run the sample, or create my own ContextMenu, the menus only end up with the items explicitly placed in there. "Duplicate in New Tab" and the other menu items are not present.

              If no context menu is set, the frame work is generating that menu for it and that generated menu is what I want to add to.

              Comment


                #8
                Hello ntbone,

                I just want to say I have received your note and I will be looking into this further.

                Thanks for your patience.


                EDIT: Looking into this further and also using Windows Inspect tool, I cannot find a way to add to the background ContextMenu.

                We can get this if our main grid is Transparent, but I could not advise a way to add items to that particular ContextMenu because it is not provided from an already available control. You could subscribe to ContextMenuOpening and ContextMenuClosing events, but would not be able to add the ContextMenu of a tab or window as you will receive null reference exceptions since ContextMenu is null.

                My recommendation would be to use a Transparent background so the tab ContextMenu items are available, and to have a large control or other grid for your custom ContextMenu items.
                Last edited by NinjaTrader_Jim; 04-01-2021, 10:53 AM.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ZenCortexCLICK, Today, 04:58 AM
                0 responses
                2 views
                0 likes
                Last Post ZenCortexCLICK  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                172 responses
                2,280 views
                0 likes
                Last Post sidlercom80  
                Started by Irukandji, Yesterday, 02:53 AM
                2 responses
                17 views
                0 likes
                Last Post Irukandji  
                Started by adeelshahzad, Today, 03:54 AM
                0 responses
                4 views
                0 likes
                Last Post adeelshahzad  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X