DrawingGroup.Opacity プロパティ


この DrawingGroup の不透明度を取得または設定します。Gets or sets the opacity of this DrawingGroup.

 property double Opacity { double get(); void set(double value); };
public double Opacity { get; set; }
member this.Opacity : double with get, set
Public Property Opacity As Double


この DrawingGroup の不透明度を表す 0 ~ 1 の値。A value between 0 and 1, inclusive, that describes the opacity of this DrawingGroup. 既定値は 1です。The default is 1.

この例では、 Drawingの不透明度を変更する方法を示します。This example shows how to modify the opacity of a Drawing. クラスは、 Opacityプロパティを持つ唯一Drawingの種類のオブジェクトです。 DrawingGroupThe DrawingGroup class is the only type of Drawing object that has an Opacity property.

Drawingオブジェクトの不透明度を変更するにはDrawingGroup 、オブジェクトをに追加しOpacityDrawingGroupオブジェクトのプロパティを設定します。To change the opacity of a Drawing object, add it to a DrawingGroup and set the Opacity property of the DrawingGroup object.

Opacity DrawingGroup Brush GeometryDrawing Opacityオブジェクトの設定には、子描画の不透明度が乗算されます。たとえば、のが0.5 で、不透明度が 50% のが含まれている場合、ブラシは25になります。 DrawingGroup非透過パーセント (0.5 * 0.5)。The Opacity setting of the DrawingGroup object is multiplied by the opacity of its child drawings; for example, if a DrawingGroup has an Opacity of 0.5 and it contains a GeometryDrawing that has a 50 percent opaque Brush, the brush is 25 percent opaque (0.5 * 0.5).

描画の部分の選択の不透明度を変更するにはOpacityMask、を使用します。To alter the opacity of select portions of a drawing, use an OpacityMask.

次の例ではDrawingGroup 、を使用GeometryDrawingして複数のオブジェクトを結合します。The following example uses a DrawingGroup to combine several GeometryDrawing objects. また、この例では、 DrawingGroupオブジェクトの不透明度を0.25 に設定して、描画の不透明度を 25% に設定しています。The example also sets the opacity of the DrawingGroup object to 0.25 so that the drawings are 25 percent opaque.

この図Opacityは、 DrawingGroupが0.25 に設定される前と後を示しています。This illustration shows the DrawingGroup before and after its Opacity is set to 0.25.

不透明度の設定が異なる図面グループDrawingGroups with different opacity settings

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SDKSample
    public class OpacityExample : Page
        public OpacityExample()

            // Create a GeometryDrawing.

            // Define the drawing's contents.
            PathFigure pLineFigure = new PathFigure();
            pLineFigure.StartPoint = new Point(25, 25);
            PolyLineSegment pLineSegment = new PolyLineSegment();
            pLineSegment.Points.Add(new Point(0, 50));
            pLineSegment.Points.Add(new Point(25, 75));
            pLineSegment.Points.Add(new Point(50, 50));
            pLineSegment.Points.Add(new Point(25, 25));
            pLineSegment.Points.Add(new Point(25, 0));
            PathGeometry pGeometry = new PathGeometry();

            GeometryDrawing drawing1 = new GeometryDrawing(
                    new Pen(Brushes.Black, 10),

            // Create another GeometryDrawing.
            GeometryDrawing drawing2 = new GeometryDrawing(
                    new Pen(Brushes.Black, 2),
                    new EllipseGeometry(new Point(10, 10), 5, 5)

            // Create the DrawingGroup and add the
            // geometry drawings.
            DrawingGroup aDrawingGroup = new DrawingGroup();

            // Set the opacity of the DrawingGroup to 0.25.
            aDrawingGroup.Opacity = 0.25;

            // Use an Image control and a DrawingImage to
            // display the drawing.
            DrawingImage aDrawingImage = new DrawingImage(aDrawingGroup);

            // Freeze the DrawingImage for performance benefits.

            Image anImage = new Image();
            anImage.Source = aDrawingImage;
            anImage.Stretch = Stretch.None;
            anImage.HorizontalAlignment = HorizontalAlignment.Left;

            // Create a border around the images and add it to the
            // page.
            Border imageBorder = new Border();
            imageBorder.BorderBrush = Brushes.Gray;
            imageBorder.BorderThickness = new Thickness(1);
            imageBorder.VerticalAlignment = VerticalAlignment.Top;
            imageBorder.HorizontalAlignment = HorizontalAlignment.Left;
            imageBorder.Margin = new Thickness(20);
            imageBorder.Child = anImage;

            this.Background = Brushes.White;
            this.Margin = new Thickness(20);
            this.Content = imageBorder;
  Background="White" Margin="20">
  <Border BorderBrush="Gray" BorderThickness="1" 
    HorizontalAlignment="Left" VerticalAlignment="Top"
    <Image Stretch="None">
        <DrawingImage PresentationOptions:Freeze="True">

            <!-- The drawing group, with an Opacity of 0.25. -->
            <DrawingGroup Opacity="0.25">
              <GeometryDrawing Brush="Lime" Geometry="M 25,25 L 0,50 25,75 50,50 25,25 25,0">
                  <Pen Thickness="10" Brush="Black" />
              <GeometryDrawing Brush="Lime">
                  <EllipseGeometry Center="10,10" RadiusX="5" RadiusY="5" />
                  <Pen Thickness="2" Brush="Black" />



値がの1場合は、 DrawingGroupが完全に不透明であること0を示します。値がの場合は、完全に透過的であることを示します。A value of 1 specifies that the DrawingGroup is completely opaque; a value of 0 specifies that it is completely transparent. 0未満の値は0として扱われ、1より大きい値は1として扱われます。A value that is less than 0 is treated as 0, and a value that is larger than 1 is treated as 1.

の不透明度GeometryDrawingを制御するもう1つの方法はOpacity 、のBrushを指定することです。Another way to control the opacity of a GeometryDrawing is to specify the Opacity of its Brush.

DrawingGroup操作は次の順序で適用されます。DrawingGroup operations are applied in the following order:

  1. OpacityMask

  2. Opacity

  3. BitmapEffect

  4. ClipGeometry

  5. GuidelineSet

  6. Transform

依存プロパティ情報Dependency Property Information

識別子フィールドIdentifier field OpacityProperty
メタデータプロパティがに設定されるtrueMetadata properties set to true NoneNone