Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Change RangeCursor opacity programatically

Solved!
Go to solution

Hi, I'm trying to change the look of Graph's RangeCursor programatically.

This is what I have

 

rangeCursor.Visibility = System.Windows.Visibility.Visible;
rangeCursor.CrosshairBrush = Brushes.Red;
rangeCursor.FillBrush = Brushes.Red;
rangeCursor.FillBrush.Opacity = 0.25f;

 

Everything works until the last line where I try to set opacity.  I get this error:

 

A first chance exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll

Additional information: Cannot set a property on object '#FFFF0000' because it is in a read-only state.

If there is a handler for this exception, the program may be safely continued.

 

Is there a way to avoid it?  I actually don't even need to change the opacity programatically but when I set FillBrush to Red it changes XAML hardcoded setting of 25% to 100%.  So that's why I am trying to add this line.

Thanks!

0 Kudos
Message 1 of 3
(3,792 Views)
Solution
Accepted by topic author kirko7

The WPF Brushes class returns shared brushes that are in a frozen (read-only) state. This avoids a local change to a brush effecting every other object in the application that happened to use that same brush.


As described in the Freezable Objects Overview, to modify a frozen object just call the Clone method and set Opacity on the result.

~ Paul H
0 Kudos
Message 2 of 3
(3,786 Views)

Thank you!

0 Kudos
Message 3 of 3
(3,772 Views)