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

textblock or box to menu

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

    textblock or box to menu

    Hello, i am wondering what is the best way to add a textbox input zone to a menu added as a menu item
    I have an existing menu and use the System.Windows.Controls.Slider - but would like to add some rows to be able to input some prices in a text box / text block or richtext block whichever is better.
    Do i add this as a menuitem and in the callback added then parse the data and then check the data.
    Ie if i only want a number int or double .. if any text it would not be processed.

    I do use XAML for other things and you can add in some rules for this on values - but would like similar in add in C# to the existing menu
    Any insight or examples of this would be appreciated
    thanks
    Last edited by soulfx; 10-09-2023, 02:29 PM.

    #2
    Hello soulfx,

    Generally a textbox would be required for inputting text or numbers. In a menu you would have to experiment on WPF controls that look how you want and also act how you wanted to ensure you get the right control for the purpose. You would need to see external WPF/Xaml examples for guides on how to embed different controls in a menu. You can find one sample that works with menus here https://ninjatrader.com/support/foru...27&postcount=1

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, yes i figured the textbox was the one to initially try with. So i have added to my existing menu with some settings eg :

      topMenuItemTextBoxSettle.Width = 100;
      topMenuItemTextBoxSettle.Height = 20;

      topMenuItemTextBoxSettle.AcceptsReturn = false;
      topMenuItemTextBoxSettle.Focusable = true;
      topMenuItemTextBoxSettle.TabIndex = 0;

      topMenuItemTextBoxSettle.IsEnabled = true;

      topMenuItemTextBoxSettle.TextChanged += topMenuItemTextBoxSettle_TextChanged;

      and the callback is being called but only if i enter space or delete - but as soon as i try to input anything other than space bar the keyboard focus goes to the ninja menu for shortcuts etc ie when you type on a chart the lookup that appears.

      So how to get keyboard focus on this is not clear
      Also ideally i only want the callback when user has finished typing and selects return (yes i see Acceptsreturn is = false but made no difference)

      I wonder if xaml is better way to go (but intermixing existing menu with xaml likely does not work) but in theory i should be able to do this in c# as i already have an existing menu with menu items.

      Need to parse and check the field as will only contain numbers and decimal

      There must be a way to manage this and parse the text with some validation options as in xaml - i will keep digging around online but seems a dearth of examples on this. So any input appreciated

      I dont think those examples i have seen before cover textbox and primarily is buttons etc​
      Last edited by soulfx; 10-10-2023, 04:30 AM.

      Comment


        #4
        Hello soulfx,

        If you are having trouble with keyboard focus you would have to implement a similar approach to the following sample by using the previewkey event on whatever is taking focus. The sample uses the ChartControl, from a menu I would not be sure what specifically has focus in that situation so you may need to experiment. The concept would be the same, when you locate what has focus you need to handle the event using previewkey events so that the default action does not happen.



        In regard to only calling the event once the final text has been entered I would not be sure how you could do that from a textbox, the end result text would not be known ahead of time to know the user was done typing. You may be able to make your own WPF control that works in a specific way so that you can add additional logic to the textbox default events.
        JesseNinjaTrader Customer Service

        Comment


          #5
          thanks will talk a look - going to be a fiddly trial error process here - may review

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rhyminkevin, Today, 04:58 PM
          3 responses
          48 views
          0 likes
          Last Post Anfedport  
          Started by iceman2018, Today, 05:07 PM
          0 responses
          5 views
          0 likes
          Last Post iceman2018  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          7 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          50 views
          0 likes
          Last Post futtrader  
          Working...
          X