Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting properties in a class

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

    Setting properties in a class

    I am using a helper class and I set a lot of properties from that class.

    Example :

    Code:
    public class Helper
    {
          public Brush thisBrush = Brushes.Red;
          public SharpDX.Direct2D1.Brush thisBrushDx  = null;
    }
    
    
    In my indicator properties section :
    
    [XmlIgnore]
    public Brush thisBrush
    {
           get { return helper.thisBrush; }
    	set 
    	{ 
    		helper.thisBrush = value;
    				
    		if( helper.thisBrush == null )
    		   return;
    			
    		if( helper.thisBrush.IsFrozen)
    		    helper.thisBrush= helper.thisBrush.Clone();
    				
    		helper.thisBrush.Freeze();
    				
    	  }
    }
    		
    [Browsable(false)]
    public string ThisBrushSerialize
    {
    	get { return Serialize.BrushToString(thisBrush); }
    	set { thisBrush = Serialize.StringToBrush(value); }
    }
    
    public override void OnRenderTargetChanged()
    {
          if(helper.thisBrushDx != null)
            helper.thisBrushDx.Dispose();
    
          if(RenderTarget != null)
          {
                helper.thisBrushDx = helper.thisBrush.ToDxBrush(RenderTarget);
          }
    }
    
    
    And on StateChange
    if(State == State.Terminated)
    {
        if(helper.thisBrushDx != null)
        {
             helper.thisBrushDx.Dispose();
             helper.thisBrushDx = null;
        }
    }

    I am not using State.SetDefaults from OnStateChange() at all to set Brush and SharpDx.Direct2D1.Brush.


    Is that the right pattern to use ?
    Am I wrong in some way ?

    #2
    Hello blar58,

    Thanks for opening the thread.

    As far as I can tell you are serializing the brushes correctly, freezing when you are supposed to and are recreating DxBrushes within the context of OnRenderTargetChanged() as is directed in our help guide.

    As the code is, I get an error when adding the indicator to a chart when I include the helper class. You may wish to use a static class instead to hold a certain data for your Brushes within a helper class.

    Our colleague Jesse has a good sample script that demonstrates using static classes to hold some information external to a NinjaScript. http://ninjatrader.com/support/forum...24&postcount=3

    Best practices for using Brushes and using SharpDx for custom rendering can be referenced below.

    Working with Brushes - https://ninjatrader.com/support/help...th_brushes.htm

    Using SharpDx for Custom Rendering - https://ninjatrader.com/support/help..._rendering.htm

    Please let me know if I may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    650 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    577 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X