Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExpandableObject won't update text on property change in the UI

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

    ExpandableObject won't update text on property change in the UI

    Hi, I have the following sample code which uses an expandable object converter to display and configure my object inside the indicator properties. It works all well, except for one small detail - when the property changes, it does not update the displayed text and only updates if I close and open the indicators window. Please refer to the animation below. How do I fix that so it updates just like plots for example? Thanks in advance!

    Code:
    using NinjaTrader.Gui;
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    
    namespace NinjaTrader.NinjaScript.Indicators.Samples
    {
        public class SampleExpandableObjectIndicator : Indicator
        {
            [TypeConverter(typeof(ExpandableObjectConverter))]
            public class MyObject : NotifyPropertyChangedBase, ICloneable
            {
                public bool Boolean { get; set; }
                public int Number { get; set; }
                public string Text { get; set; }
    
                public MyObject() : this(true, 256, "Hello World!") { }
    
                public MyObject(bool boolean, int number, string text)
                {
                    Boolean = boolean;
                    Number = number;
                    Text = text;
                }
    
                public object Clone()
                {
                    return new MyObject(Boolean, Number, Text);
                }
    
                public override string ToString()
                {
                    return string.Format("{0}, {1}, {2}", Boolean, Number, Text);
                }
            }
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name = "Expandable Object";
                    Object = new MyObject();
                }
            }
    
            [Display(Name = "My object")]
            public MyObject Object { get; set; }
        }
    }
    MyObject (won't update the text)
    Click image for larger version

Name:	UVcGCjT.gif
Views:	236
Size:	21.7 KB
ID:	1179130
    Plot (updates the text when property changed)
    Click image for larger version

Name:	NAn84AO.gif
Views:	189
Size:	38.6 KB
ID:	1179131

    #2
    I figured it out - had to add RefreshPropertiesAttribute to the properties. Below is the updated code as a reference for others that might encounter the same problem.

    Code:
    using NinjaTrader.Gui;
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    
    namespace NinjaTrader.NinjaScript.Indicators.Samples
    {
        public class SampleExpandableObjectIndicator : Indicator
        {
            [TypeConverter(typeof(ExpandableObjectConverter))]
            public class MyObject : NotifyPropertyChangedBase, ICloneable
            {
                [RefreshProperties(RefreshProperties.Repaint)]
                public bool Boolean { get; set; }
    
                [RefreshProperties(RefreshProperties.Repaint)]
                public int Number { get; set; }
    
                [RefreshProperties(RefreshProperties.Repaint)]
                public string Text { get; set; }
    
                public MyObject() : this(true, 256, "Hello World!") { }
    
                public MyObject(bool boolean, int number, string text)
                {
                    Boolean = boolean;
                    Number = number;
                    Text = text;
                }
    
                public object Clone()
                {
                    return new MyObject(Boolean, Number, Text);
                }
    
                public override string ToString()
                {
                    return string.Format("{0}, {1}, {2}", Boolean, Number, Text);
                }
            }
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name = "Expandable Object";
                    Object = new MyObject();
    
                    AddPlot(System.Windows.Media.Brushes.Red, "Result");
                }
            }
    
            [Display(Name = "My object")]
            public MyObject Object { get; set; }
        }
    }
    Last edited by Jiri_Beloch; 11-22-2021, 07:23 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    626 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    359 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    562 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    567 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X