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)
{
if (myChart == null)
sampleButton = new Button
{
myChart.MainMenu.Add(sampleButton);
sampleButton.Click += SampleButton_Click;
System.Windows.Automation.AutomationProperties.Set AutomationId(sampleButton, "SampleButton");
private void SampleButton_Click(object sender, RoutedEventArgs e)
{
Comment