• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add a property editor to an NTWindow

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

    Add a property editor to an NTWindow

    I'm trying to display a property editor for an object that is not an indicator.
    The object may have nested objects and definitely has Brush (color) properties. I'd like the property editor to behave like the property editor for an indicator.
    Is there a way to add a NinjaTrader property editor to an NTWindow to edit my object? Here's a little example code that needs to have the "blanks" filled in.

    public class Settings {
    public int A { get; set; }
    public SubSettings B { get; set; }
    public Brush C { get; set; }
    public Settings() {
    A = 1;
    B = new SubSettings();
    C = new SolidColorBrush(Colors.WhiteSmoke);
    }
    }

    public class SubSettings {
    public int A { get; set; }
    public Brush B { get; set; }
    public SubSettings() {
    A = 10;
    B = new SolidColorBrush(Colors.Red);
    }
    }

    class PropertyEditorWindow : NTWindow {
    Settings _editingObject;
    public PropertyEditorWindow() {
    Caption = "Editor";
    // add some control here to display properties
    }
    public Settings EditingObject {
    get { return _editingObject; }
    set {
    _editingObject = value;
    // do something here to display the properties of this settings object
    }
    }
    }

    static class ExampleUsage {
    public static void DoExample() {
    var settings = new Settings();
    var editor = new PropertyEditorWindow();
    editor.EditingObject = settings;
    editor.Show();
    }
    }
    Many thanks!

    #2
    Thank you for your question bboyle1234.

    Ninja does not have a public documented PropertyEditor screen, and so you will need to create this window in XAML using the guidelines here,
    http://ninjatrader.com/support/helpG...don_window.htm

    Once this is set up, one challenge you will run into is serializing and unserializing brushes by name, for example, "ForestGreen" in Brushes.ForestGreen . The attached code will help with this, and should serve as a guide for marshalling (serializing) other objects. These six lines of code from this sample will help you set up a color selector as well, since they loop through all the named colors :

    Code:
    
                Type colors = typeof(System.Windows.Media.Colors);
                foreach(var prop in colors.GetProperties())
                {
                    if(((System.Windows.Media.Color)prop.GetValue(null, null)) == color)
                        return prop.Name;
                }
    
    We are happy to help with any questions that come up during the process of setting up this screen.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      There is one more hint I can provide. You mentioned needing nested menus as well. This publicly available tutorial will demonstrate creating tree views in C# with WPF.

      https://www.codeproject.com/Articles...ee-View-in-WPF
      Jessica P.NinjaTrader Customer Service

      Comment


        #4
        NinjaTrader uses the WPFPropertyGrid by DenisVuyka.
        https://github.com/DenisVuyka/WPG/wiki

        You assign an object to display in the control through its SelectedObject property.

        Comment


          #5
          Thanks to all who contributed, here is the solution I ended up using:
          Code:
          using NinjaTrader.Gui.Tools;
          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows.Media;
          using System.Windows.Controls.WpfPropertyGrid;
          using System.Windows.Controls;
          using System.Windows;
          
          namespace NinjaTrader.Custom.AddOns {
              class PropertyEditorWindow : NTWindow {
          
                  PropertyEditorWindow(string caption, object editingObject) {
                      Caption = caption;
                      Width = 400;
                      Height = 600;
          
                      var grid = new Grid();
                      Content = grid;
                      grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
                      grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
                      grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40, GridUnitType.Pixel) });
          
                      var scrollViewer = new ScrollViewer();
                      grid.Children.Add(scrollViewer);
                      Grid.SetColumn(scrollViewer, 0);
                      Grid.SetRow(scrollViewer, 0);
                      scrollViewer.HorizontalAlignment = HorizontalAlignment.Stretch;
                      scrollViewer.VerticalAlignment = VerticalAlignment.Stretch;
          
                      var pg = new PropertyGrid();
                      scrollViewer.Content = pg;
                      pg.HorizontalAlignment = HorizontalAlignment.Stretch;
                      pg.VerticalAlignment = VerticalAlignment.Stretch;
                      pg.SelectedObject = editingObject;
          
                      var buttonStackPanel = new StackPanel();
                      grid.Children.Add(buttonStackPanel);
                      Grid.SetColumn(buttonStackPanel, 0);
                      Grid.SetRow(buttonStackPanel, 1);
                      buttonStackPanel.Orientation = Orientation.Horizontal;
                      buttonStackPanel.HorizontalAlignment = HorizontalAlignment.Right;
                      buttonStackPanel.FlowDirection = FlowDirection.RightToLeft;
          
                      var buttonStyle = Application.Current.TryFindResource("SuperDomQuickButton") as Style;
          
                      var bCancel = new Button {
                          Content = "Cancel",
                          Style = buttonStyle,
                          Margin = new Thickness(10, 0, 10, 0),
                          IsCancel = true,
                          Width = 98,
                      };
                      buttonStackPanel.Children.Add(bCancel);
          
                      var bOK = new Button {
                          Content = "OK",
                          Style = buttonStyle,
                          Margin = new Thickness(10, 0, 10, 0),
                          IsDefault = true,
                          Width = 98,
                      };
                      buttonStackPanel.Children.Add(bOK);
                      bOK.Click += (s, e) => {
                          DialogResult = true;
                          Close();
                      };
          
                  }
                  public static bool TryEdit(Window owner, string caption, object selectedObject) {
                      var window = new PropertyEditorWindow(caption, selectedObject);
                      window.Owner = owner;
                      return window.ShowDialog() ?? false;
                  }
              }
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rudccv, Today, 08:42 PM
          0 responses
          3 views
          0 likes
          Last Post rudccv
          by rudccv
           
          Started by Newtrader101, Today, 03:54 PM
          1 response
          15 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by williamzz, Today, 03:28 PM
          0 responses
          7 views
          0 likes
          Last Post williamzz  
          Started by Robert87, Today, 11:07 AM
          0 responses
          14 views
          0 likes
          Last Post Robert87  
          Started by phta123, Today, 10:24 AM
          0 responses
          17 views
          0 likes
          Last Post phta123
          by phta123
           
          Working...
          X