DrawingContext dc = // Obtain the DrawingContext object from a visual object dc.PushOpacity(0.5); dc.DrawRectangle(Brushes.Blue, null, new Rect(10, 10, 100, 100)); dc.Pop();
DrawingContext dc = // Obtain the DrawingContext object from a visual object dc.PushOpacity(0.5); dc.DrawRectangle(Brushes.Blue, null, new Rect(10, 10, 100, 100)); dc.PushOpacity(0.7); dc.DrawRectangle(Brushes.Green, null, new Rect(25, 25, 70, 70)); dc.Pop(); dc.Pop();In this example, the first rectangle has an opacity level of 0.5, while the nested rectangle has an opacity level of 0.7. This creates a translucent effect where the nested rectangle appears darker than the first rectangle. The System.Windows.Media namespace is part of the .NET Framework and is included in the PresentationCore.dll package library.