Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Attach WPF button to specific panel instead of chart-top?

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

    Attach WPF button to specific panel instead of chart-top?

    Hello all,

    I've been looking at the SampleWPFModifications file, and I love that the examples in the sample do not clutter up the actual chart with buttons:


    Specifically regarding the button row under "use case #1" (the horizontal/top row drop-down menu and button):

    I'd like that button row to attach itself directly to the panels of indicators it gets incorporated into, rather than attaching itself above all the panels as it currently does. In other words, if I add the button row's code to a particular indicator so I can make certain values of that indicator faster to change, I'd like the row to attach itself along the bottom (preferably) of that specific indicator's panel on the chart. Then, the button would always be directly next to the indicator it's manipulating, regardless of the order in which any indicators were added (especially helpful if planning to add buttons to several indicators/panels).

    Does anyone know if it is even possible to attach that button row directly to its indicator's panel? If it is, any ideas on how to make it happen? I've tried tweaking some things that appear related to that goal, but all I manage to do is break the script.

    Thanks muchly


    #2
    Anyone know if it's possible, and how I could do it?

    Comment


      #3
      Hello TakeFlight,

      Instead of adding the button or menu to the WPF of the window, if you want to add a control to the chart area of a panel, add the control the UserControlCollection.

      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you for responding. I have seen various scripts around that demonstrate adding buttons directly to charts. The problem is, putting buttons directly on a chart clutters up the chart (tends to cover the candlesticks or indicator plots, which interferes with both visibility and chart interaction, such as adding or moving drawings). I'm hoping to avoid adding things directly to the chart/indicators themselves to limit that problem as much as possible.

        I really like the WPF button-ribbon type of row created by "use case #1" of the SampleWPFModifications script because it does not clutter the chart itself, leaving visibility and interactivity fully in tact. I'm wondering if it's possible to instruct that button ribbon thing to append itself to the top or bottom of a specific panel, rather than above all the panels as it's currently programmed to do. For example, telling the button ribbon to wait for the indicator to do the initial load (thus NT has assigned its panel #), then obtain that panel # and attach itself to that (or, I guess you could say, insert itself between that panel and the one directly above or below it, like a separator).

        In other words, if I add that WPF code to an indicator (one that creates its own panel when loaded on a chart window), I want the code to identify that specific indicator's panel # and put itself next to that panel (top or bottom, but preferably bottom).

        I see in the "HideWPFControls" and "ShowWPFControls" sections of the code that the script appears to basically count the existing panels and then move everything down one to make room for itself, but I'm not fully understanding how to modify this to accommodate a different placement than directly at the top of the chart window. I would think this is possible... the script even seems to play nice enough with itself if I load two instances of that code (added into different indicators, but in the same chart window): in that case, it just creates two ribbons at the top (stacked). So I would think there's a way to get it to play nice with stacking the ribbon in a different relationship with the other panels, such as directly alongside the indicator its code has been added into...

        Is that even possible?​

        Comment


          #5
          Hello TakeFlight,

          Thank you for your note.

          Unfortunately, you can choose to either add a row to the WPF grid above the chart control or you can add controls the UserControlCollection.

          A toolbar on a panel would be over the chart control and would be the UserControlCollection.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thank you for responding.

            So... you're saying I can't instruct the WPF grid to attach itself between charts... what about at least moving the WPF grid to the bottom of the chart window, below all the panels?

            I've tried to move it to the bottom, by tweaking settings in the "HideWPFControls" and "ShowWPFControls" sections of the code (which appear to be the only parts of the code that affect where the button panel gets placed in relation to the window and other panels), to try to at least achieve that much (moving the buttons to the bottom). Unfortunately, I only manage to break the script: It either fails altogether (won't load), or it "loads" but with an almost-all-gray background (as though the WPF grid takes over the entire chart).

            Even that much would help. I want to be able to separate certain kinds of buttons (along the top) from other kinds of buttons, not just stack everything in several crammed-together rows. But separated horizontal rows will work better for my next goal than the sample vertical button panels, so I'd love a way to move some instances of the horizontal buttons lower. Since the WPF sample shows that every other placement location is possible for adding buttons/menus (vertical lefthand, vertical righthand, horizontal top-of-chart, horizontal top-of-window where default drop-down menus are, and even in Chart Trader itself), I'm assuming bottom of chart window is also possible and just not represented in that sample file... and I'm hoping it's just a couple simple adjustments to make "use case #1" do that.

            So, is it possible to modify the code to at least make it display (properly, unlike my failed attempt) at the bottom?​

            If so, which parts of the script would I need to modify? Would it only be code in the Hide/Show WPF Controls sections, as I suspect, or am I missing other sections that affect the script's relationship to the window? I tried making minor changes to some of the code, but I'm still a novice with C# (and NinjaScript), so I'm not familiar with more complex codes yet or what some of the nondescript variables are meant to reference.

            Thanks again. I hope it's possible to move the WPF grid to the bottom, at least, and that it's not too complicated.

            Comment


              #7
              Hello TakeFlight,

              There is only one SharpDX RenderTarget and one ChartControl. The panels rendered on the rendertarget are just different rendered lines to show where one panel ends and another begins.

              This is not a WPF area. It is a single ChartControl object that contains the tab control and sharpdx render target.

              The UserControlCollection is a transparent WPF layer on top the chart control. You can add WPF controls to that.

              "So... you're saying I can't instruct the WPF grid to attach itself between charts​"

              If by charts you mean panels (and not separate chart windows), that is correct. There is no separation between the panels on the sharpdx rendertarget.

              "Unfortunately, I only manage to break the script: It either fails altogether (won't load)"

              What are the run-time errors showing on the Log tab of the Control Center?

              "or it "loads" but with an almost-all-gray background (as though the WPF grid takes over the entire chart)"

              Are you specifying the correct row definitions and heights for the rows you are adding?
              Are you moving the UIElement objects to the correct rows?

              "So, is it possible to modify the code to at least make it display (properly, unlike my failed attempt) at the bottom?​"

              Yes, the way that the SampleWPFModifications script is adding a row to the grid above chartcontrol for the custom top toolbar, you can add a row below the chart control. Note, you have to actually add 2 rows, because the grid starts with no rows. The first row becomes the chartcontrol row, then you would move your object to the 2nd row.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello TakeFlight,

                I was having a thought about this and maybe you could just add the indicator to it's own panel and and the controls to the UserControlCollection.

                I made a video that demonstrates.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi ChelseaB,

                  I saw your first message, and proceeded to do as you suggested (adding another row) over the subsequent 2-3 days... But, I apologize, I never saw the second message from you until today. So, first, I want to thank you for the suggestion and for taking the time to make a video demonstration of your suggestion. That's great!

                  I appreciate the suggestion. I actually ended up with a similar idea, inspired by reading your message where you said, "If by charts you mean panels ..." (yes, I did mean panels, sorry). Don't ask me why, but that popped the thought in my head of wondering if it would work to basically turn the buttons into their own indicator, rather than relying on the WPF row at bottom, so I can attach a panel with nothing but the buttons right beside the indicator the buttons are designed to control (to keep the buttons closer to their target). I haven't tested it yet, because I've been considering which method I'd ultimately like better before I put the work into it (probably the separate indicator, as long as the two indicators talk nicely to each other).

                  In the meantime, I was happy to hear it's at least possible to move the row to the bottom... That was hopeful and gave me the boost to keep trying.​ To that end, I did end up adding another row to the WPF script, as you appeared to be suggesting:

                  "Note, you have to actually add 2 rows, because the grid starts with no rows. The first row becomes the chartcontrol row, then you would move your object to the 2nd row."

                  It took some time to figure out exactly what portions of the code needed to be duplicated and how, and then the lovely tedious task of modifying all the zillions of little variables to new terms. Spent a few hours at it all. Unfortunately, it still wasn't working right by the time I finished: I managed to get a second blank row showing, but the buttons that should have been showing as row 2 were on row 1, and row 1's buttons weren't showing at all (I figured row 1 was behind row 2).

                  After much frustration and fiddling with things, I finally figured it out. I had to add a "+1" to one tiny line of code, and then it moved that new set of buttons to the second row like it should be. When that worked, I wondered if changing it to +2 would accomplish my ultimate goal -- and it did! That finally moved the extra row to the bottom of the chart window, while the first row of buttons remained at the top of the chart window. Success!

                  After figuring out where to add the +1/+2, that got me to thinking: It seems like the original WPF sample already has two rows, technically, because it creates a row and assigns the chart panels to that, then creates another row to add the buttons to that row. It made me wonder if I even needed to add in another row before I could move it to the bottom. I revisited the original upper row code from the sample WPF script (without my extra row added). As it turns out, the simple "+1" still worked, without any extra rows or fiddling.

                  Here's what worked. In the "private void ShowWPFControls()" section, add +1 per the following to move the existing row to the bottom:

                  Code:
                  tabControlStartRow = Grid.GetRow(chartWindow.MainTabControl) + 1;​
                  That's it. If I want that existing row to stay at top but an additional row at bottom, I can leave that line of code alone, add all the code for a new row, and add +2 to the new row's code instead.

                  Before I posted the question here, I had been adjusting numbers in other parts (which wasn't working), but I hadn't made the connection that that line was what required the adjustment until now. Still learning this stuff. Wish I'd realized sooner that it was such a simple, 2-second fix! Would have saved an enormous amount of time. But, hey, maybe this will save the next person some time if another novice wants to do that same thing!

                  ... And now, after all the time I spent trying to figure it out, it turns out I might not even use that method for the intended script anyway ... Ah, the nature of scripting. I just wish I could script my plotting indicator to call on the second (button) indicator (to auto-load the second indicator onto the chart), the same way it works with the "Plotting from within a NinjaScript Strategy" concept​. But I guess I'll survive if I have to manually attach the two indicators separately!

                  Thanks again for the help, suggestions, and video! I hope I won't run into issues when I start making my buttons -- but I guess I'll be back here if I do.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  596 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  343 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  103 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  556 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  554 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X