DrawingGroup.Transform 屬性


取得或設定套用至這個 TransformDrawingGroupGets or sets the Transform that is applied to this DrawingGroup.

 property System::Windows::Media::Transform ^ Transform { System::Windows::Media::Transform ^ get(); void set(System::Windows::Media::Transform ^ value); };
public System.Windows.Media.Transform Transform { get; set; }
member this.Transform : System.Windows.Media.Transform with get, set
Public Property Transform As Transform



套用至這個 DrawingGroup 的轉換。The transformation to apply to this DrawingGroup. 預設為 nullThe default is null.


此範例顯示如何將套用 TransformDrawingThis example shows how to apply a Transform to a Drawing. 若要轉換 Drawing 物件,請將它加入至 DrawingGroup ,並設定 Transform 物件的屬性 DrawingGroupTo transform a Drawing object, you add it to a DrawingGroup and set the Transform property of the DrawingGroup object.

DrawingGroup類別是唯一 Drawing 支援轉換的物件類型。The DrawingGroup class is the only type of Drawing object that supports transforms. 若要將多個轉換套用至單一 DrawingGroup ,請使用 TransformGroupTo apply multiple transforms to a single DrawingGroup, use a TransformGroup.

下列範例會使用 DrawingGroup 來合併數個 GeometryDrawing 物件,然後使用來轉換它們 RotateTransformThe following example uses a DrawingGroup to combine several GeometryDrawing objects and then transforms them by using a RotateTransform.

下圖顯示套用 DrawingGroup 之前和之後的 RotateTransformThe illustration shows the DrawingGroup before and after the RotateTransform is applied.

旋轉後的 DrawingGroupA rotated DrawingGroup

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 TransformExample : Page

        public TransformExample()

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

            // Create a RotateTransform and apply it to the
            // drawing group.
            RotateTransform rotation = new RotateTransform(
                45, // Angle 
                50, // CenterX
                75  // CenterY
            aDrawingGroup.Transform = rotation;

            // 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" HorizontalAlignment="Left">
        <DrawingImage PresentationOptions:Freeze="True">

            <!-- A drawing group with a RotateTransform. -->
              <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" />

              <!-- Rotate the drawing 45 degrees about (50,75). -->
                <RotateTransform CenterX="50" CenterY="75" Angle="45" />




若要將多個轉換套用至單一 DrawingGroup ,請使用 TransformGroupTo apply multiple transforms to a single DrawingGroup, use a TransformGroup.

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 TransformProperty
中繼資料屬性設定為 trueMetadata properties set to true None