DrawingGroup.Opacity Propiedad

Definición

Obtiene o establece la opacidad de este objeto DrawingGroup.Gets or sets the opacity of this DrawingGroup.

public:
 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

Valor de propiedad

Valor entre 0 y 1, ambos incluidos, que describe la opacidad de este objeto DrawingGroup.A value between 0 and 1, inclusive, that describes the opacity of this DrawingGroup. El valor predeterminado es 1.The default is 1.

Ejemplos

En este ejemplo se muestra cómo modificar la opacidad de Drawingun.This example shows how to modify the opacity of a Drawing. La DrawingGroup clase es el único tipo de Drawing objeto que tiene una Opacity propiedad.The DrawingGroup class is the only type of Drawing object that has an Opacity property.

Para cambiar la opacidad de un Drawing objeto, agréguelo DrawingGroup a y DrawingGroup establezca la Opacity propiedad del objeto.To change the opacity of a Drawing object, add it to a DrawingGroup and set the Opacity property of the DrawingGroup object.

La Opacity configuración Opacity DrawingGroup GeometryDrawing Brushdel objeto se multiplica por la opacidad de sus dibujos secundarios; por ejemplo, si un tiene un de 0,5 y contiene un que tiene un 50 por ciento opaco, el pincel es 25. DrawingGroup porcentaje opaco (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).

Para modificar la opacidad de las partes seleccionadas de un dibujo, use OpacityMask.To alter the opacity of select portions of a drawing, use an OpacityMask.

DrawingGroup En el ejemplo siguiente se utiliza para combinar GeometryDrawing varios objetos.The following example uses a DrawingGroup to combine several GeometryDrawing objects. En el ejemplo también se establece la opacidad DrawingGroup del objeto en 0,25 para que los dibujos sean opacos en un 25 por ciento.The example also sets the opacity of the DrawingGroup object to 0.25 so that the drawings are 25 percent opaque.

En esta ilustración se DrawingGroup muestra el anterior y Opacity el después de su establecido en 0,25.This illustration shows the DrawingGroup before and after its Opacity is set to 0.25.

![DrawingGroups con diferentes valores de opacidad] (~/add/media/graphicsmm-opacity.png "DrawingGroups con diferentes valores de opacidad")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));
            pLineFigure.Segments.Add(pLineSegment);
            PathGeometry pGeometry = new PathGeometry();
            pGeometry.Figures.Add(pLineFigure);

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

            //
            // Create another GeometryDrawing.
            //
            GeometryDrawing drawing2 = new GeometryDrawing(
                    Brushes.Lime,
                    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();
            aDrawingGroup.Children.Add(drawing1);
            aDrawingGroup.Children.Add(drawing2);

            //
            // 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.
            aDrawingImage.Freeze();

            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;

        }
    }
}
<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="PresentationOptions"
  Background="White" Margin="20">
  <Border BorderBrush="Gray" BorderThickness="1" 
    HorizontalAlignment="Left" VerticalAlignment="Top"
    Margin="20">
    <Image Stretch="None">
      <Image.Source>
        <DrawingImage PresentationOptions:Freeze="True">
          <DrawingImage.Drawing>

            <!-- 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">
                <GeometryDrawing.Pen>
                  <Pen Thickness="10" Brush="Black" />
                </GeometryDrawing.Pen>
              </GeometryDrawing>
              <GeometryDrawing Brush="Lime">
                <GeometryDrawing.Geometry>
                  <EllipseGeometry Center="10,10" RadiusX="5" RadiusY="5" />
                </GeometryDrawing.Geometry>
                <GeometryDrawing.Pen>
                  <Pen Thickness="2" Brush="Black" />
                </GeometryDrawing.Pen>
              </GeometryDrawing>
            </DrawingGroup>
          </DrawingImage.Drawing>
        </DrawingImage>
      </Image.Source>
    </Image>
  </Border>


</Page>

Comentarios

Un valor de 1 especifica que el DrawingGroup es completamente opaco; un valor de 0 especifica que es completamente transparente.A value of 1 specifies that the DrawingGroup is completely opaque; a value of 0 specifies that it is completely transparent. Un valor menor que 0 se trata como 0, y un valor mayor que 1 se trata como 1.A value that is less than 0 is treated as 0, and a value that is larger than 1 is treated as 1.

Otra manera de controlar la opacidad de un GeometryDrawing es especificar el Opacity de su Brush.Another way to control the opacity of a GeometryDrawing is to specify the Opacity of its Brush.

DrawingGrouplas operaciones se aplican en el orden siguiente:DrawingGroup operations are applied in the following order:

  1. OpacityMask

  2. Opacity

  3. BitmapEffect

  4. ClipGeometry

  5. GuidelineSet

  6. Transform

Información sobre propiedades de dependenciaDependency Property Information

Campo de identificadorIdentifier field OpacityProperty
Propiedades de metadatos establecidas entrueMetadata properties set to true NingunaNone

Se aplica a

Consulte también: