11-17-2015 11:58 AM
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!
Solved! Go to Solution.
11-17-2015 01:46 PM
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.
11-18-2015 08:15 AM
Thank you!