Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rectangle problem when using PropertyGrid control

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

    Rectangle problem when using PropertyGrid control

    Hey guys,

    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:

    Click image for larger version

Name:	propertygridproblem.png
Views:	111
Size:	2.4 KB
ID:	1330694

    Here's a code sample to reproduce the problem:

    Code:
    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();
            }
        }
    }​
    Does anyone know where the problem comes from? Or the solution to the problem?

    Thanks


    #2
    Hello rafaelcoisa,

    Unfortunately, our support team cannot provide much assistance with using 3rd party libraries, but I can provide an example that uses a property grid from this library you may find helpful.

    SetIndicatorValueFromAddonWindowPropertyGridExampl e_NT8 - https://forum.ninjatrader.com/forum/...egy#post774548

    This thread will remain open for any community members that would like to provide insight and experience.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      hey NinjaTrader_ChelseaB

      I think I found the source of all the problems.
      There is something in these DataTemplates that I need to change.
      Do you have a hint?

      Code:
      <DataTemplate
          x:Key="{x:Static wpg:EditorKeys.DefaultCategoryEditorKey}">
          <Grid>
              <Grid.ColumnDefinitions>
                  <ColumnDefinition />
                  <ColumnDefinition
                      Width="{Binding Source={StaticResource BorderThinThickness}}" />
                  <ColumnDefinition />
              </Grid.ColumnDefinitions>
              <design:PropertyItemsLayout
                  Grid.ColumnSpan="3"
                  IsTabStop="False"
                  ItemsSource="{Binding Properties}" />
              <Rectangle
                  x:Name="sep"
                  Stretch="Fill"
                  Grid.Column="1"
                  Fill="{StaticResource PropertyGridSeparatorLineFill}">
                  <FrameworkElement.Margin>
                      <MultiBinding
                          Converter="{StaticResource MultiThicknessConverter}">
                          <Binding
                              Source="0" />
                          <Binding
                              Source="0" />
                          <Binding
                              Source="0" />
                          <Binding
                              ConverterParameter="-1"
                              Source="{StaticResource MarginWindowControl}"
                              Converter="{StaticResource ThicknessWithMultiplierConverter}" />
                      </MultiBinding>
                  </FrameworkElement.Margin>
              </Rectangle>
          </Grid>
      </DataTemplate    
      
      <DataTemplate
          x:Key="{x:Static wpg:EditorKeys.ComplexPropertyEditorKey}"
          DataType="wpg:PropertyItemValue">
          <Grid>
              <Grid.RowDefinitions>
                  <RowDefinition
                      Height="Auto" />
                  <RowDefinition />
              </Grid.RowDefinitions>
              <Expander
                  Style="{StaticResource ComplexPropertyExpander}"
                  IsExpanded="{Binding ParentProperty.IsExpanded, Mode=TwoWay}"
                  Header="{Binding ParentProperty.DisplayName, Mode=TwoWay}">
                  <AutomationProperties.AutomationId>
                      <MultiBinding
                          StringFormat="ComplexEditor_{0}_{1}_Expander">
                          <Binding
                              Path="ParentProperty.PropertyDescriptor.ComponentType.Name" />
                          <Binding
                              Path="ParentProperty.PropertyDescriptor.Name" />
                      </MultiBinding>
                  </AutomationProperties.AutomationId>
              </Expander>
              <design:PropertyItemsLayout
                  Grid.Row="1"
                  IsTabStop="False"
                  ItemsSource="{Binding SubProperties}"
                  IsEnabled="{Binding IsEditable}"
                  Visibility="{Binding ParentProperty.IsExpanded, Converter={StaticResource BoolToVisibility}}">
                  <FrameworkElement.Tag>
                      <Thickness
                          Left="{StaticResource MarginBase}" />
                  </FrameworkElement.Tag>
              </design:PropertyItemsLayout>
          </Grid>
      </DataTemplate>​

      Comment


        #4
        Hello rafaelcoisa,

        Unfortunately, this would be beyond what our support team is allowed to assist with.

        This thread will remain open for any community members that would like to provide insight and experience.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        556 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X