Set the Background property to mutable Brush (instead of the immutable Brushes.White type). For example, you can create a SolidColorBrush :
var background = new SolidColorBrush(Colors.White); panel.Background = background;
Now you can change the Opacity property of this brush in your program.
background.Opacity = 0.5;
You can also do this with any other brush, like GradientBrush or ImageBrush , etc.
source share