Hello, everyone. Bit of a stumper here.
This code produces no grid on the chart. Can anyone explain why?
ChartControl.Dispatcher.InvokeAsync((() =>
{
myGrid2 = ChartControl.FindName("myCustomGrid") as System.Windows.Controls.Grid;
if (myGrid2 != null)
{
Print("Grid found! Indicator 1 - myCustomGrid = " + myGrid2.Name.ToString());
}
else if (myGrid2 == null) /* create the grid */
{
myGrid2 = new System.Windows.Controls.Grid
{
Name = "myCustomGrid", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom
};
System.Windows.Controls.ColumnDefinition column1 = new System.Windows.Controls.ColumnDefinition();
column1.Width = new GridLength(80);
System.Windows.Controls.ColumnDefinition column2 = new System.Windows.Controls.ColumnDefinition();
column2.Width = new GridLength(140);
System.Windows.Controls.ColumnDefinition column3 = new System.Windows.Controls.ColumnDefinition();
column3.Width = new GridLength(140);
System.Windows.Controls.ColumnDefinition column4 = new System.Windows.Controls.ColumnDefinition();
column4.Width = new GridLength(140);
System.Windows.Controls.ColumnDefinition column5 = new System.Windows.Controls.ColumnDefinition();
column5.Width = new GridLength(40);
System.Windows.Controls.ColumnDefinition column6 = new System.Windows.Controls.ColumnDefinition();
column6.Width = new GridLength(40);
myGrid2.ColumnDefinitions.Add(column1);
myGrid2.ColumnDefinitions.Add(column2);
myGrid2.ColumnDefinitions.Add(column3);
myGrid2.ColumnDefinitions.Add(column4);
myGrid2.ColumnDefinitions.Add(column5);
myGrid2.ColumnDefinitions.Add(column6);
System.Windows.Controls.RowDefinition row1 = new System.Windows.Controls.RowDefinition();
System.Windows.Controls.RowDefinition row2 = new System.Windows.Controls.RowDefinition();
System.Windows.Controls.RowDefinition row3 = new System.Windows.Controls.RowDefinition();
row1.Height = new GridLength(35);
row2.Height = new GridLength(35);
row3.Height = new GridLength(7);
myGrid2.RowDefinitions.Add(row1);
myGrid2.RowDefinitions.Add(row2);
myGrid2.RowDefinitions.Add(row3);
autoOrder = new System.Windows.Controls.Button
{
Name = "AutoOrder",
Content = "Manual Order",
Foreground = Brushes.White,
Background = Brushes.DarkGreen,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Normal
};
exitNow = new System.Windows.Controls.Button
{
Name = "ExitNow",
Content = "Exit Now",
Foreground = Brushes.White,
Background = Brushes.Firebrick,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Bold
};
visLine = new System.Windows.Controls.Button
{
Name = "ShowLine",
Content = "Show Line",
Foreground = Brushes.Black,
Background = Brushes.Goldenrod,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Normal
};
myTextBox = new NumericTextBox
{
Name = "ValueInputBox",
//ValueType = "{x:Type system:double}",
Width = 80,
Text = _customControlText // Default value
};
bE10 = new System.Windows.Controls.Button
{
Name = "bE+10",
Content = "+10",
Foreground = Brushes.Black,
Background = Brushes.Gray,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Bold
};
bE1 = new System.Windows.Controls.Button
{
Name = "bE+1",
Content = "+1",
Foreground = Brushes.Black,
Background = Brushes.Gray,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Bold
};
bE010 = new System.Windows.Controls.Button
{
Name = "bE-10",
Content = "-10",
Foreground = Brushes.Black,
Background = Brushes.Gray,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Bold
};
bE01 = new System.Windows.Controls.Button
{
Name = "bE-1",
Content = "-1",
Foreground = Brushes.Black,
Background = Brushes.Gray,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Bold
};
// Subscribe to the button's click event to execute the logic we defined in OnMyButtonClick()
autoOrder.Click += OnMyButtonClick;
exitNow.Click += ExitNowClick;
visLine.Click += ShowLineClick;
bE1.Click += bE1Click;
bE10.Click += bE10Click;
bE010.Click += bE010Click;
bE01.Click += bE01Click;
// Define where the buttons should appear in the grid
System.Windows.Controls.Grid.SetColumn(myTextBox, 0);
System.Windows.Controls.Grid.SetColumn(visLine, 1);
System.Windows.Controls.Grid.SetColumn(autoOrder, 2);
System.Windows.Controls.Grid.SetColumn(exitNow, 3);
System.Windows.Controls.Grid.SetColumn(bE1, 4);
System.Windows.Controls.Grid.SetColumn(bE10, 5);
System.Windows.Controls.Grid.SetColumn(bE010, 5);
System.Windows.Controls.Grid.SetColumn(bE01, 4);
System.Windows.Controls.Grid.SetRow(myTextBox, 1);
System.Windows.Controls.Grid.SetRow(visLine, 1);
System.Windows.Controls.Grid.SetRow(autoOrder, 1);
System.Windows.Controls.Grid.SetRow(exitNow, 1);
System.Windows.Controls.Grid.SetRow(bE1, 0);
System.Windows.Controls.Grid.SetRow(bE10, 0);
System.Windows.Controls.Grid.SetRow(bE010, 1);
System.Windows.Controls.Grid.SetRow(bE01, 1);
// Add the button as child to the custom grid
myGrid2.Children.Add(bE1);
myGrid2.Children.Add(bE10);
myGrid2.Children.Add(myTextBox);
myGrid2.Children.Add(visLine);
myGrid2.Children.Add(autoOrder);
myGrid2.Children.Add(exitNow);
myGrid2.Children.Add(bE01);
myGrid2.Children.Add(bE010);
// Finally, add the completed grid to the custom NinjaTrader UserControlCollection
UserControlCollection.Add(myGrid2);
Print("New grid - Indicator 1 - myCustomGrid = " + myGrid2.Name.ToString());
}
}));
It generates no errors. Even the Log tab in Control Center is silent. I don’t see the Print output, either.
The irritating thing is that it works just fine if I remove all of the code for the bE* buttons. I actually just added those, but, being functionally identical to the previously existing, successfully functioning buttons, there is no possible explanation (that I can see) for why this grid doesn’t load.
Any ideas?