I'm trying to use the PropertyGrid control from the WpfPropertyGrid library.
But I'm having a weird problem.
If I change where the PropertyGrid is located, a gray rectangle appears above the control.
Here's the screenshot of the problem:
Here's a code sample to reproduce the problem:
using System.Windows.Controls;
using System.Windows.Controls.WpfPropertyGrid;
///NinjaTrader.Code.Output.Process("".ToString(), PrintTo.OutputTab1);
//This namespace holds Add ons in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.AddOns
{
#region AddOnBase
public class PropertyGridProblem : NinjaTrader.NinjaScript.AddOnBase
{
private ControlCenter controlCenter;
private NTMenuItem existingMenuItem;
private NTMenuItem newMenuItem;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"";
Name = "PropertyGridProblem";
}
else if (State == State.Configure)
{
}
}
protected override void OnWindowCreated(Window window)
{
controlCenter = window as ControlCenter;
if (controlCenter == null)
return;
existingMenuItem = controlCenter.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
if (existingMenuItem == null)
return;
newMenuItem = new NTMenuItem { Header = "PropertyGridProblem", Style = Application.Current.TryFindResource("MainMenuItem") as Style };
existingMenuItem.Items.Add(newMenuItem);
newMenuItem.Click += OnMenuItemClick;
}
protected override void OnWindowDestroyed(Window window)
{
if (newMenuItem == null || !(window is ControlCenter))
return;
if (existingMenuItem == null || !existingMenuItem.Items.Contains(newMenuItem))
return;
newMenuItem.Click -= OnMenuItemClick;
existingMenuItem.Items.Remove(newMenuItem);
newMenuItem = null;
}
private void OnMenuItemClick(object sender, RoutedEventArgs e)
{
NinjaTrader.Core.Globals.RandomDispatcher.InvokeAsync(new Action(() => new PropertyGridProblemWin().Show()));
}
}
#endregion
public class PropertyGridProblemWin : NTWindow
{
private Grid root;
private Grid grid_Level1;
private Border border_first_inside_Level1;
private Grid grid_receive_pg;
private PropertyGrid pg;
private PgClassTest pgClassTest = new PgClassTest();
public PropertyGridProblemWin()
{
Caption = "PropertyGridProblemWin";
BuildGrid();
AddChild(root);
}
private void BuildGrid()
{
root = new Grid();
ColumnDefinition root_ColumnDefinition0 = new ColumnDefinition() { Width = new GridLength(3, GridUnitType.Star) };
ColumnDefinition root_ColumnDefinition1 = new ColumnDefinition() { Width = GridLength.Auto };
root.ColumnDefinitions.Add(root_ColumnDefinition0);
root.ColumnDefinitions.Add(root_ColumnDefinition1);
grid_Level1 = new Grid();
//Grid.SetColumn(grid_Level1, 0);///no error
Grid.SetColumn(grid_Level1, 1); ///error! [rectangle above control]
border_first_inside_Level1 = new Border();
grid_receive_pg = new Grid();
pg = new PropertyGrid(){ SelectedObject = pgClassTest, PropertyDisplayMode = PropertyDisplayMode.Native };
grid_receive_pg.Children.Add(pg);
border_first_inside_Level1.Child = grid_receive_pg;
grid_Level1.Children.Add(border_first_inside_Level1);
root.Children.Add(grid_Level1);
}
}
public class PgClassTest
{
public BarsPeriod BarsPeriod { get; set; }
public PgClassTest()
{
BarsPeriod = new BarsPeriod();
}
}
}
Thanks

Comment