Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Through ADD ON, Access/Get Specific Chart Window (out of several open chart windows)

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

    Through ADD ON, Access/Get Specific Chart Window (out of several open chart windows)

    Hi,

    While developing an NT8 ADDON, I have come across a bottleneck and to get out of this, I seek experts help. In OnWindowCreated(), I check whether the new window is a chart. If yes, I add a button to the chart. Then on button click I use GetWindow Function to get a sort of reference/pointer to the chart and do some modifications with the objects on the chart (for example add or delete custom buttons). The same thing explained here can also be viewed in short code I have attached below.

    The problem starts when I open a second chart. Now, OnWindowCreated(), myChart and myChart1 in the code below both point towards the second chart and if I click the button on the first chart, I get errors like the object is owned by another thread and cannot be accessed.

    My need is that on button click, I can get reference/pointer to the chart window from which the button was pressed and do modifications in the objects on that particular chart.
    It's probably possible with one or a few lines of code but I got stuck here and could not develop that despite huge efforts. Will be thankful if an expert can get me out of this.
    The related piece of code is given below.

    Gui.Chart.Chart myChart, myChart1, chartWindow;
    protected override void OnWindowCreated(Window window)
    {
    myChart = window as Gui.Chart.Chart;
    if (myChart == null)
    return;
    myChart1 = myChart;
    sampleButton = new Button
    {
    Content = " PSC ",
    Style = System.Windows.Application.Current.TryFindResource ("Button") as Style
    };
    myChart.MainMenu.Add(sampleButton);
    sampleButton.Click += SampleButton_Click;
    System.Windows.Automation.AutomationProperties.Set AutomationId(sampleButton, "SampleButton");
    }

    private void SampleButton_Click(object sender, RoutedEventArgs e)
    {
    chartWindow = System.Windows.Window.GetWindow(myChart1.ActiveCha rtControl.Parent) as Gui.Chart.Chart;
    }


    #2
    Hi Mubeen, thanks for writing in.

    Tapping into chart objects is not an officially supported feature so support for this will be limited. There is an existing example here that adds buttons to the SuperDOM:

    https://ninjatraderecosystem.com/use...s-to-superdom/

    Notice that the "AddButtonsMethod" is called using a dispatcher, and the variables are local to the method only (no class level properties such as Gui.Chart.Chart myChart, myChart1, chartWindow)

    See also this example that loops through the workspace and gets every open ChartControl object, it might be helpful:
    https://ninjatrader.com/support/foru...ons#post837439

    Since this is more of a WPF/C# related issue, I will unfortunately not be able to research any further into the WPF/C# topics.

    Kind regards,
    -ChrisL

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jdr120, Today, 07:31 AM
    0 responses
    2 views
    0 likes
    Last Post jdr120
    by jdr120
     
    Started by jipsonmv, Today, 06:51 AM
    0 responses
    8 views
    0 likes
    Last Post jipsonmv  
    Started by harr5754, Today, 06:28 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by aelagha, Today, 12:21 AM
    0 responses
    20 views
    0 likes
    Last Post aelagha
    by aelagha
     
    Started by rcrook23, Today, 03:06 AM
    1 response
    16 views
    0 likes
    Last Post rcrook23  
    Working...
    X