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

Grid row does not add

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

    Grid row does not add

    Hi,
    I am using below code in my indicator and printing for debugging:

    protected void CreateWPFControls()
    {
    chartWindow = System.Windows.Window.GetWindow(ChartControl.Paren t) as Chart;
    chartGrid = chartWindow.MainTabControl.Parent as System.Windows.Controls.Grid;

    buttonGrid = new System.Windows.Controls.Grid();

    int tabShowing = chartGrid.Children.Count - 3;
    Print(" 1 : " + tabShowing);
    if (tabShowing < 1)
    {
    buttonGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(210) });
    Print("start count : " + buttonGrid.Children.Count);
    Print(" 1.1 : " + tabShowing);
    }
    else
    {
    Print(" 2 : " + tabShowing);
    int count = tabShowing;
    Print("Before count : " + buttonGrid.Children.Count);
    buttonGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(50 * count) });
    Print("after count : " + buttonGrid.Children.Count);
    }

    TextBlock label = new TextBlock()
    {
    Width = 200,
    Height = 100
    };

    Print(" 3 : " + tabShowing);

    for (int i = tabShowing; i < tabShowing + 1; i++)
    {
    Grid.SetRow(label, i);
    buttonGrid.Children.Add(label);
    Print(i+"============");
    }
    }

    So from my debuggin through printing, I found though
    if (tabShowing < 1)
    is true, still
    buttonGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(210) });

    is not adding the row and again when it goes to else following other actions, it does not execute

    buttonGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(50 * count) });

    Any reason, why it does not execute, as my printing of buttonGrid.Children.Count shows 0

    Can anyone advise please?

    #2
    Hello asmmbillah,

    From the given code nothing stands out. This is really not enough information for an observer to provide an answer. You could try adding more prints to see if your conditions are becoming true or not, you can also try removing the conditions to always add the row to make sure its not a problem with that code.

    One note is that if count variable is 0, 50 times 0 is 0; if you tried to make the grid 0 size that would not work.

    Please let me know if I may be of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. I have tested, conditions are becoming true. And count variable will only multiply with 50 for GridLength when its value is >=1, as you can see in the conditions. I have, as you advised, removed the conditions to check with before and after Print("after count : " + buttonGrid.Children.Count); still it shows count 0. Please advise.

      Comment


        #4
        Hello asmmbillah,

        I still wouldn't be able to say from the given information. If you want to form a very sample sample without any conditions and attach that we could take a look from there.

        As a test just try to add the rows you want without any other logic such as math or conditions, that will tell you if your logic/conditions is part of the problem or if what you are otherwise trying to do is the problem.


        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for your reply. I tried my best to trim it down to min. please see the attached.
          Attached Files

          Comment


            #6
            Hi, any update on that sample script you requested and I attached above?

            Comment


              #7
              Hello asmmbillah,

              Thanks for the reply.

              I reviewed the code however it is not clear what your goal is here, have you tried my prior suggestion or to use specific indexes and not use any type of conditions/logic to set the rows? I don't know what look you are after here with the rows to advise further, if you want to specify what you want exactly using indexes I could try to see what may be happening surrounding that. What I mean is to remove the loops and other conditions you made and just simply add the rows to the control. If you get the expected output you could look at adding back the other logic, otherwise if it looks wrong we can review that in contrast to a description of what you wanted to see.

              This is otherwise a situation where you will need to debug or try different values to see what works for the use case, we don't have specific guidelines surrounding WPF development so you are free to add the row however it ends up working.


              Please let me know if I may be of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thanks for your reply.
                When i am adding first instance of the indicator, it is adding the label ie Textblock to the column it adds, now when I add the second instance of the indicator, I just want the label to be added below the label added on the first instance of the indicator on the same column, so that it does not overlaps. Simple something similar can be seen in a tabcontrol, but it is not a tab control I am adding, I am adding label on the same column for multiple instances of same indicator and labels should be added one below another. I hope that clarifies.

                Comment


                  #9
                  Hello asmmbillah,

                  If your situation involves using two indicator instances you would need to include that kind of detail with your question, that was not apparent from the given details.

                  For cases where you need to find an existing item it would be suggested to assign that item an automation id. It looks like we covered this previously in one of your other posts: https://ninjatrader.com/support/foru...52#post1109152

                  You could assign an automation ID to your parent grid using SetAutomationId, if you need to find it later from either another instance or a different script you can use that ID to locate that control. You would either locate it like the sample I had linked to or you can use the FindFirst method on any parent UserControl.

                  After checking if the grid exists or not you could either create the grid/sidebar or append a child to it. You would also need to use the SetRow on the control if you place it in a grid with row definitions, you will also need to modify the existing definitions if you add new rows. These are concepts which I cannot provide in depth education for but you can learn about in external C#/WPF development tutorials. Creating a WPF application in visual studio can also help to learn XAML design or allow you to test adding different controls to grids in a more simple way.



                  Please let me know if I may be of further assistance.

                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks for your reply. I have applied, that autimation id concept from you script, but it does not locate id of the label in my sample attached. Therefore, the whole process is not working. I am not asking for help with wpf or any other issue. I am seeking support about locating that id which I have set using the sample in your script when I add the 2nd instance. I hope, that gives you further clarification and root cause. Please note, i am adding the label into the buttongrid, as you can see in my sample srcript.

                    Comment


                      #11
                      Hello asmmbillah,

                      The testGridRow.zip you attached does not the concepts from the sample I linked to. You are using loops and other conditions to try and locate the control. If you want to use loops and conditions you will have to debug that further to see why that's not working.

                      If you have tried to apply the automation ID concept but it did not work then you would need to review what you tried and try again. The sample I linked to works and would be the same concept for any other type of WPF control if you want to find it.

                      I could suggest using that sample as a starting point to debugging the problem as that already works. Other areas in the platform also use automation ID's to allow you to find those controls such as the chart trader, that is the normal way to mark a control so it can be found.



                      Please let me know if I may be of further assistance.


                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by PhillT, Today, 02:16 PM
                      2 responses
                      3 views
                      0 likes
                      Last Post PhillT
                      by PhillT
                       
                      Started by Kaledus, Today, 01:29 PM
                      3 responses
                      9 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by frankthearm, Yesterday, 09:08 AM
                      14 responses
                      47 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by gentlebenthebear, Today, 01:30 AM
                      2 responses
                      13 views
                      0 likes
                      Last Post gentlebenthebear  
                      Started by PaulMohn, Today, 12:36 PM
                      2 responses
                      17 views
                      0 likes
                      Last Post PaulMohn  
                      Working...
                      X