Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

correct destructor code for the addOn example in learning resources

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

    correct destructor code for the addOn example in learning resources

    Hi All

    I'm new to C# programming so maybe this is obvious but I couldn't find correct solution yet. I'd need help for coding the correct destructor that deletes the created panel dynamically. In this page there is an example code for adding new panel from the AddOn to chart windows top: https://ninjatrader.com/support/help...erence_wip.htm

    Code:
    protected override void OnWindowCreated(Window window)
    {
    // Obtain a reference to any chart that triggered OnWindowCreated
    Chart Window = window as Chart;
    
    // Instantiate a grid to hold a reference to the content of the chart window
    Grid mainWindowGrid = Window.Content as Grid;
    
    // Add existing row definition for existing row if it is not present
    if (mainWindowGrid.RowDefinitions.Count == 0)
    {
    mainWindowGrid.RowDefinitions.Add(new RowDefinition());
    }
    
    // Instantiate a RowDefinition and set its height
    RowDefinition row = new RowDefinition();
    row.Height = new GridLength(PanelLength);
    
    // Insert the new row into the chart's main window grid
    mainWindowGrid.RowDefinitions.Insert(0, row);
    
    //Move Existing Elements down one row, since our new content will take the top row
    foreach (UIElement element in mainWindowGrid.Children)
    {
    element.SetValue(Grid.RowProperty, (int)element.GetValue(Grid.RowProperty) + 1);
    }
    
    //Create the Top Panel grid and add it to our newly defined row
    Grid Panel = new Grid();
    Panel.SetValue(Grid.RowProperty, 0);
    mainWindowGrid.Children.Add(Panel);
    
    //Create a sample text block and add it to the Top/Bottom Panel Grid.
    TextBlock TextBlock = new TextBlock();
    TextBlock.Text = PanelDirection.ToString() + " Panel (" + PanelLocation.ToString() + ") Sample Text Block";
    TextBlock.Foreground = Brushes.Red;
    TextBlock.SetValue(Grid.RowProperty, 0);
    Panel.Children.Add(TextBlock);
    }
    ​So what would be the correct destructor for this? In the examples there is destructor for another example but not for this one and I could'nt find the right way to delete panels and move the remaining ones to return to the basic state of the chart.

    cheers

    #2
    Hello vesipeto,

    Thanks for your post.

    It seems that you are modifying a chart window from an addon using OnWindowCreated.

    Please see the reference sample linked below that demonstrates using WPF to add items to a chart's rows and removes them in the terminated states.



    Let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    630 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    566 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X