Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Working around BackBrush.Opacity is in read-only mode

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

    Working around BackBrush.Opacity is in read-only mode

    I have found and read the following post regarding this topic:
    https://ninjatrader.com/support/foru...read-only-mode

    It is not clear to me hot to accomplish setting an opacity value to a background color.

    I am using to UI Properties to obtain the brush color and the opacity value.

    Brush: hTFBullishTrendBackgroundColor

    Opacity as an integer: hTFBullishBackgroundOpacity


    Code:
    if (Closes[1][0] > Closes[1][1])
    
    {
    
    
    
    Brush hTFBullishTrendBackgroundColorCopy = hTFBullishTrendBackgroundColor;
    
    hTFBullishTrendBackgroundColorCopy.Opacity = hTFBullishBackgroundOpacity/100d;
    
    hTFBullishTrendBackgroundColorCopy.Freeze();
    
    BackBrush = hTFBullishTrendBackgroundColorCopy;
    
    }

    I don't want to use SolidColorBrush to define the brush and transparency value as I am getting this information from the user.


    What I am missing? When I ran this code I get the following error:

    Code:
     Error on calling 'OnBarUpdate' method on bar 95: Cannot set a property on object '#FF3E3D42' because it is in a read-only state.

    #2
    Hello GARZONJ,

    You will need to use a SolidColorBrush to define opacity so that part is going to be required, that is needed if you are copying a color so you can access the Color property.

    You also need to create a new brush that is not already created, you can't modify opacity on an existing brush. In what you provided I don't see that part.

    Code:
    SolidColorBrush existingBrush = (SolidColorBrush)UserInputBrushHere; //cast to solidcolor so you can access .Color
    Brush newBackBrush = new SolidColorBrush(existingBrush.Color);  // make a brand new brush using the existing color infomration
    The other post is really the bare minimum at what you would need to copy the existing brush information and make a new brush with an opacity. You can find more information about working with brushes here: https://ninjatrader.com/support/help...gcustombrushes

    If you are taking user input the other post would provide a good structure for taking the color input. You could replace BackBrush in that sample with your user input brush, the null check should not be needed if you are setting a default.
    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 08-04-2020, 11:43 AM.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jerminedop, Today, 12:18 AM
    0 responses
    5 views
    0 likes
    Last Post jerminedop  
    Started by cnzaxtoil, Yesterday, 11:38 PM
    0 responses
    4 views
    0 likes
    Last Post cnzaxtoil  
    Started by cnzaxtoil, Yesterday, 11:37 PM
    0 responses
    3 views
    0 likes
    Last Post cnzaxtoil  
    Started by sukhob, Yesterday, 04:27 PM
    1 response
    14 views
    0 likes
    Last Post zacharydw00  
    Started by Bmnaiorwsd, Yesterday, 07:52 PM
    0 responses
    4 views
    0 likes
    Last Post Bmnaiorwsd  
    Working...
    X