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

Prevent TextBlock in MainMenu from Receiving Focus

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

    Prevent TextBlock in MainMenu from Receiving Focus

    In an AddOn, I add a TextBlock to the NTWindow.MainMenu. No problem. However, the TextBlock is focusable, which is a problem.

    How do I prevent it receiving focus? I have tried:
    Code:
    textblock.Focusable = false;
    textblock.I****TestVisible = false;
    textblock.IsEnabled = false;
    textblock.FocusVisualStyle = null;
    Aside: I have to laugh: the second attribute name is "Is Hit Test Visible (but without spaces)" but the Forum editor thinks it contains a swear word and automatically substitutes "****" for the relevant letters.

    Anyway, grateful for ideas.

    Thanks.
    Last edited by jeronymite; 07-26-2022, 03:27 AM.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #2
    Hello jeronymite,

    What is the overall goal for that textbox? Are you trying to make a menu item similar to the existing items in the main menu?

    A textbox should be focusable because its intended for user input. You would have to disable the control to prevent it from being focusable by any number of different WPF events. You could use a Label instead which has no means to input text and that would not be focusable. Alternatively if this is meant to be a menu item then you should use the appropriate MenuItem type instead of TextBox.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your response, Jesse.

      First, this is a TextBlock, not a TextBox. Also, I have tried a Label with the same result. It is intended as a readonly notification text. Each Add to NTWindow.MainMenu, which may or may not be adding a menu, adds a separate control to the Title Bar. I have easily added a main menu control with menu items, and Buttons that can perform particular actions. Now I want to add to the Title Bar, using exactly the same approach, a readonly, non-focusable text block.

      As stated already, I have tried all the various approaches above to try to prevent it being focusable, but it still highlights as focussed on mouse hover.

      Minimal example code attached.

      Your further thoughts appreciated.

      Thanks.
      Attached Files
      Last edited by jeronymite; 07-27-2022, 03:34 AM. Reason: Edit: Added minimal code example.
      Multi-Dimensional Managed Trading
      jeronymite
      NinjaTrader Ecosystem Vendor - Mizpah Software

      Comment


        #4
        Hello jeronymite,

        You could search online for other possible ways to prevent focus however focus is a part of WPF framework. The platform has built styles for most standard controls so mouse over actions and other actions which are used with existing controls would apply to custom controls as well. You can set the Style to null however it will look strange with the platform styles by doing that.





        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks, Jesse.

          The TextBlock Style is already null, and although the TextBlock has a TriggerCollection, the Count is zero.

          NTWindow.MainMenu is ObservableCollection<object>.

          Can you think of any other approach to adding a readonly, non-focusable, text-based object to the NTWindow Title Bar?

          Thanks.
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment


            #6
            Hello jeronymite,

            You can try a label in place of the TextBlock however you are adding the items to the menu so any menu related styles would apply to the menu item you added. Basically all wpf controls that are used in the platform have styles which relate to their own use and some more complex items like MenuItem or NTMenuItem would have styles that also encompass the content of the item.

            To be able to avoid any platform relates styling such as the focus in menus you would have to make your own menu without any styling like a base WPF control. That would let you use any styles or properties directly with that control and without existing skin/resource dictionary items overriding that.

            The better alternative because you made your own window would be to not use the menu at all and place this just below the titlebar inside the windows content area. That wouldn't have the focus styling like the menu does, the menu should have focus highlights just like any other window in the platform.

            Another alternative is to not use a TextBlock at all and use the menu as it is intended to be used, that would involve using a NTMenuItem. This won't let you style like a TextBlock but would let you put text in the titlebar without the blue border. The blue borders just how the menu handles arbitrary controls being added in place of an actual menu item.


            Code:
            Gui.Tools.NTMenuItem topMenuItem = new Gui.Tools.NTMenuItem()
            {
                Header = "Menu 1",
               Foreground = Brushes.PowderBlue,
               Margin = new System.Windows.Thickness(0),
               Padding = new System.Windows.Thickness(1),
               VerticalAlignment = VerticalAlignment.Center,
               Style = System.Windows.Application.Current.TryFindResource ("MainMenuItem") as Style
            };
            
            NTWindow wnd = new TestNTWindow();
            wnd.MainMenu.Add(topMenuItem);
            wnd.Show();
            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




            JesseNinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_Jesse The NTMenuItem is an elegant, simple, supported solution to the original request: Add a readonly, non-focusable, text-based object to the NTWindow Title Bar.

              Thank you, Jesse! Most appreciative of your assistance with this. Thanks also to NinjaTrader_ChelseaB for the referenced code.

              Thanks.
              Multi-Dimensional Managed Trading
              jeronymite
              NinjaTrader Ecosystem Vendor - Mizpah Software

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by traderqz, Today, 12:06 AM
              10 responses
              18 views
              0 likes
              Last Post traderqz  
              Started by algospoke, 04-17-2024, 06:40 PM
              5 responses
              46 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by arvidvanstaey, Today, 02:19 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by mmckinnm, Today, 01:34 PM
              3 responses
              5 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by f.saeidi, Today, 01:32 PM
              2 responses
              9 views
              0 likes
              Last Post f.saeidi  
              Working...
              X