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:	241
Size:	21.7 KB
ID:	1179130
    Plot (updates the text when property changed)
    Click image for larger version

Name:	NAn84AO.gif
Views:	195
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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    57 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    78 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    41 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    101 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    61 views
    0 likes
    Last Post PaulMohn  
    Working...
    X