Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Custom ComboBox (has styles and datatemplates) to the PropertyGrid?

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

    Adding Custom ComboBox (has styles and datatemplates) to the PropertyGrid?

    Hi. Not sure if this is possible but is there a way to add to the PropertyGrid a custom ComboBox that has styles and data templates? Something similar to the ATM Strategy dropdown:

    Click image for larger version

Name:	ATMStrategy.png
Views:	1027
Size:	8.3 KB
ID:	1098813
    with groupings and a button. Not the ATM Strategy dropdown itself but something looking similar which we made. How does one go about adding this to the PropertyGrid?

    Thanks.

    #2
    Hello cmarkb,

    Thank you for your reply.

    An enum can make a combo box, but we don't have an example for adding buttons there. Custom property editors can be created, however.

    Here's one example from our help guide on customizing property grid behavior:



    Here's an example of a custom property editor (Custom PropertyEditor A.K.A custom button editor):

    IN AN ADDON, DEFINE THE CUSTOM PROPERTYEDITOR. NOTE! ANY CHANGES REQUIRE A PLATFORM RESTART FOR THIS TO BE RELOADED.

    Code:
    namespace NinjaTrader.NinjaScript.AddOns
    {
        public class TestWPFWindowSelector : System.Windows.Controls.WpfPropertyGrid.PropertyEditor
        {
            public TestWPFWindowSelector()
            {
                InlineTemplate = CreateTemplate();
            }
    
            System.Windows.DataTemplate CreateTemplate()
            {
                const string xamlTemplate = @"
    <DataTemplate >
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width=""30""/>
              <ColumnDefinition Width=""*""/>
            </Grid.ColumnDefinitions>
    
        <Button Grid.Column=""0"" Content=""..."" Padding=""0"" Margin=""0""
                  HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch""
                  HorizontalContentAlignment=""Center""
                  Style=""{x:Null}""
                  Command =""pg:PropertyEditorCommands.ShowDialogEditor""
                  CommandParameter=""{Binding}"" />
    
            <TextBox Grid.Column=""1""
                     Text=""{Binding StringValue}""
                     ToolTip=""{Binding Value}""/>
    
    
          </Grid>
        </DataTemplate>
    ";
    
                System.Windows.Markup.ParserContext context = new System.Windows.Markup.ParserContext();
                context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
                context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
                context.XmlnsDictionary.Add("pg", "http://schemas.denisvuyka.wordpress.com/wpfpropertygrid");
                System.Windows.DataTemplate template = (System.Windows.DataTemplate)System.Windows.Markup.XamlReader.Parse(xamlTemplate, context);
                return template;
            }
    
            public override void ClearValue(System.Windows.Controls.WpfPropertyGrid.PropertyItemValue propertyValue, System.Windows.IInputElement commandSource)
            {
                if (propertyValue == null || propertyValue.IsReadOnly)
                {
                    return;
                }
                propertyValue.StringValue = string.Empty;
            }
    
            public override void ShowDialog(System.Windows.Controls.WpfPropertyGrid.PropertyItemValue propertyValue, System.Windows.IInputElement commandSource)
            {
                System.Windows.Controls.WpfPropertyGrid.PropertyGrid propGrid = commandSource as System.Windows.Controls.WpfPropertyGrid.PropertyGrid;
                if (propGrid == null) return;
    
                NinjaTrader.Gui.Tools.NTWindow myWindow = new NinjaTrader.Gui.Tools.NTWindow();
                myWindow.Width = 100;
                myWindow.Height = 100;
                myWindow.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                bool? result = myWindow.ShowDialog();
                propertyValue.StringValue = "success"; // change this string and compile, the ui does not see this change
                propGrid.DoReload();
                propGrid.RaiseEvent(new System.Windows.Controls.WpfPropertyGrid.PropertyValueChangedEventArgs(System.Windows.Controls.WpfPropertyGrid.PropertyGrid.PropertyValueChangedEvent, propertyValue.ParentProperty, ""));
            }
        }
    }
    Then, you can use the editor in a script:

    Code:
    [Display(Name = "TestProperty", GroupName = "Test")]
    [PropertyEditor("NinjaTrader.NinjaScript.AddOns.TestWPFWindowSelector")]
    public string TestProperty { get; set; }
    Also, this publicly available link will provide more information you can research on WPF Property Grid:

    WPF PropertyGrid Control. Contribute to DenysVuika/WPG development by creating an account on GitHub.


    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      Thanks for the example! And will checkout that github repo.

      Comment


        #4
        Great information. Thanks, Kate.

        The sample code at https://ninjatrader.com/support/help...r_to_custo.htm (https://ninjatrader.com/support/help...verter_NT8.zip) is also fantastic. Thanks to the author(s).

        Are there any samples that demonstrate how to create nested Property Categories? Or documentation on the matter in the context of NinjaTrader. Many NT Property Grids include such nesting.

        The other aspect of standard NT Property editing is the ability to create Property templates (save/load/etc). Documentation or samples of that would also be useful.

        In both these cases, if such samples or documentation are not available, it would be extremely useful if existing samples or documentation might be enhanced in these respects.

        Thanks.
        Multi-Dimensional Managed Trading
        jeronymite
        NinjaTrader Ecosystem Vendor - Mizpah Software

        Comment


          #5
          Hello jeronymite,

          Thank you for your reply.

          We don't support or have examples of nested property categories. However, it is possible to put an expandable class object in a gridcategory that would somewhat look like nested categories:

          https://ninjatrader.com/support/forum/forum/ninjatrader-8/indicator-development/98639-performance-optimization?p=790552#post790552

          I'm unsure what you mean by Property templates - are you referring to the strategy or indicator template? The actual template creation would be done under the hood - there would not be documentation or samples of how those are created.

          Please let us know if we may be of further assistance to you.

          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Thanks, Kate. Always appreciate your kind assistance.

            The expandable brushes example is exactly what I needed. Thanks! (Note that the link in your response has text that shows the correct link, but the underlying link itself points to a different location in the Help documentation. Just FYI.)

            As for the templates, I am indeed referring to the ability found in the selection of Indicators, for example, whereby one can create/manage a template using the Template slider at the bottom right of the Property Grid, where one can save/load/reset a template. I understand that what happens under the hood needs to be specific to the implementation; it's the Template slider control and the ability to hook to the save/load/reset methods that I'm looking for. In fact, the structure of the Indicators selection window is a more comprehensive example of the type of structure one would want -- on the left one can select an object, including add/remove/up/down capability, and on the right one has a Property Grid with the ability to create/manage templates.

            Any examples of the use of such controls, or documentation on their use, even unsupported, would be most appreciated.

            Thanks.
            Multi-Dimensional Managed Trading
            jeronymite
            NinjaTrader Ecosystem Vendor - Mizpah Software

            Comment


              #7
              Hello jeronymite,

              Thank you for your reply.

              That's strange about the link. Not certain how that happened!

              As far as templates, this would still be unsupported. Template buttons would be added in the dialog window - that's internal, and we don't have any examples for that. We also didn't see any available automation IDs you could hook into, so unfortunately there's not much we would be able to assist with there. However, I'll leave this thread open in case any of our users have been successful with unsupported code for this type of thing.

              Edit: theoretically you could make a method that writes an xml file with your scripts public properties, but to make a universal button to save all properties would likely need reflection and other unsupported methods.

              I have created a feature request to create examples of the indicator templating. This request is being tracked under the number SFT-5012.

              As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

              Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

              Please let us know if we may be of further assistance to you.
              Last edited by NinjaTrader_Kate; 08-04-2020, 09:00 AM.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Thanks for the feature request, Kate.

                Wondering if you have a variation of the sample given below where the XAML DataTemplate is used as the input to LoadXAML when creating an NTTabPage.

                Thanks.
                Multi-Dimensional Managed Trading
                jeronymite
                NinjaTrader Ecosystem Vendor - Mizpah Software

                Comment


                  #9
                  Hello jeronymite,

                  Thank you for your reply.

                  Which sample were you referring to?

                  Thanks in advance; I look forward to assisting you further.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, Kate. It's the sample in situ below in this thread (second post of the thread) that you posted called "Custom PropertyEditor".

                    Thanks.
                    Multi-Dimensional Managed Trading
                    jeronymite
                    NinjaTrader Ecosystem Vendor - Mizpah Software

                    Comment


                      #11
                      Hello jeronymite,

                      Thank you for your reply.

                      We don't have any examples that specifically use the DataTemplate class, however, the AddonShell Example found on the following forum post shows how to load from XAML in general:



                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        Hey NinjaTrader_Kate
                        And what about the customization of the category editor?
                        Like this don't work:

                        Code:
                        public class PropCategoryEditor : System.Windows.Controls.WpfPropertyGrid.CategoryEditor
                            {
                                public PropCategoryEditor()
                                {
                                    InlineTemplate = CreateTemplate();
                                }
                        
                                System.Windows.DataTemplate CreateTemplate()
                                {
                                    const string xamlTemplate = @"<DataTemplate>
                                                                    <Grid>
                                                                        <Grid.ColumnDefinitions>
                                                                            <ColumnDefinition />
                                                                            <ColumnDefinition Width=""{Binding Source={StaticResource BorderThinThickness}}"" />
                                                                            <ColumnDefinition />
                                                                        </Grid.ColumnDefinitions>
                                                                        <pg: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>";
                                    
                                    System.Windows.Markup.ParserContext context = new System.Windows.Markup.ParserContext();
                                    context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
                                    context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
                                    context.XmlnsDictionary.Add("pg", "http://schemas.denisvuyka.wordpress.com/wpfpropertygrid");
                                    System.Windows.DataTemplate template = (System.Windows.DataTemplate)System.Windows.Markup.XamlReader.Parse(xamlTemplate, context);
                                    
                                    return template;
                                }
                            }​
                        and the attribute in the class:

                        Code:
                        [CategoryEditor("Prop GroupName", typeof(PropCategoryEditor))]

                        Comment


                          #13
                          Hello,

                          Is it also possible to add an existing Strategy "enum" list as combo box to the Chart Trader grid area?

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by N1tr0, 01-02-2025, 11:25 AM
                          8 responses
                          113 views
                          0 likes
                          Last Post N1tr0
                          by N1tr0
                           
                          Started by fincabayano, Today, 05:58 AM
                          0 responses
                          10 views
                          0 likes
                          Last Post fincabayano  
                          Started by omribidi, 02-06-2025, 04:39 AM
                          2 responses
                          31 views
                          0 likes
                          Last Post omribidi  
                          Started by Aileenapu, Today, 05:34 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post Aileenapu  
                          Started by fincabayano, Today, 05:28 AM
                          0 responses
                          9 views
                          0 likes
                          Last Post fincabayano  
                          Working...
                          X