System.Windows.Media 命名空间


.NET Framework 类库
EllipseGeometry 类

更新:2007 年 11 月

表示圆或椭圆的几何图形。

命名空间:  System.Windows.Media
程序集:  PresentationCore(在 PresentationCore.dll 中)
用于 XAML 的 XMLNS:http://schemas.microsoft.com/winfx/xaml/presentation

语法

Visual Basic(声明)
Public NotInheritable Class EllipseGeometry _
    Inherits Geometry
Visual Basic (用法)
Dim instance As EllipseGeometry
C#
public sealed class EllipseGeometry : Geometry
Visual C++
public ref class EllipseGeometry sealed : public Geometry
J#
public final class EllipseGeometry extends Geometry
JScript
public final class EllipseGeometry extends Geometry
XAML 对象元素用法
<EllipseGeometry .../>
备注

EllipseGeometry 类与 Path 元素或 GeometryDrawing 一起使用可以绘制一个椭圆,将该类与 UIElementClip 属性一起使用可以定义一个椭圆形剪裁区域。EllipseGeometry 类还有很多其他用途。有关 EllipseGeometry 的更多信息,请参见Geometry 概述

EllipseGeometry 与 Ellipse 的比较

Ellipse 类具有 FillStroke 以及 EllipseGeometry 所没有的其他呈现属性。Ellipse 类是一个 FrameworkElement,因而会参与布局系统;它可用作支持 UIElement 子级的任何元素的内容。

另一方面,EllipseGeometry 类只定义椭圆的几何图形,无法呈现自身。由于它十分简单,因而用途更加广泛。

Freezable 功能

EllipseGeometry 是一种 Freezable 对象,因此可以将其冻结以提高性能。有关 Freezable 功能(例如冻结和克隆)的信息,请参见 Freezable 对象概述

示例

下面的示例使用两个 EllipseGeometry 对象来定义 GeometryDrawing 的内容。该示例产生下面的输出:

两个 EllipseGeometry 对象

两个椭圆的 GeometryDrawing
C#
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 GeometryDrawingExample : Page
    {
        public GeometryDrawingExample()
        {

            //
            // Create the Geometry to draw.
            //
            GeometryGroup ellipses = new GeometryGroup();
            ellipses.Children.Add(
                new EllipseGeometry(new Point(50,50), 45, 20)
                );
            ellipses.Children.Add(
                new EllipseGeometry(new Point(50, 50), 20, 45)
                );


            //
            // Create a GeometryDrawing.
            //
            GeometryDrawing aGeometryDrawing = new GeometryDrawing();
            aGeometryDrawing.Geometry = ellipses;

            // Paint the drawing with a gradient.
            aGeometryDrawing.Brush = 
                new LinearGradientBrush(
                    Colors.Blue, 
                    Color.FromRgb(204,204,255), 
                    new Point(0,0), 
                    new Point(1,1));

            // Outline the drawing with a solid color.
            aGeometryDrawing.Pen = new Pen(Brushes.Black, 10);

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

            // Freeze the DrawingImage for performance benefits.
            geometryImage.Freeze();

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

            //
            // Place the image inside a border and
            // add it to the page.
            //
            Border exampleBorder = new Border();
            exampleBorder.Child = anImage;
            exampleBorder.BorderBrush = Brushes.Gray;
            exampleBorder.BorderThickness = new Thickness(1);
            exampleBorder.HorizontalAlignment = HorizontalAlignment.Left;
            exampleBorder.VerticalAlignment = VerticalAlignment.Top;
            exampleBorder.Margin = new Thickness(10);

            this.Margin = new Thickness(20);
            this.Background = Brushes.White;
            this.Content = exampleBorder;
        }

    }
}
XAML
<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"
  Margin="20" Background="White">

  <Border BorderBrush="Gray" BorderThickness="1" 
    HorizontalAlignment="Left" VerticalAlignment="Top"
    Margin="10">
    <Image Stretch="None" HorizontalAlignment="Left">
      <Image.Source>
        <DrawingImage PresentationOptions:Freeze="True">
          <DrawingImage.Drawing>

            <GeometryDrawing>
              <GeometryDrawing.Geometry>

                <!-- Create a composite shape. -->
                <GeometryGroup>
                  <EllipseGeometry Center="50,50" RadiusX="45" RadiusY="20" />
                  <EllipseGeometry Center="50,50" RadiusX="20" RadiusY="45" />
                </GeometryGroup>
              </GeometryDrawing.Geometry>
              <GeometryDrawing.Brush>

                <!-- Paint the drawing with a gradient. -->
                <LinearGradientBrush>
                  <GradientStop Offset="0.0" Color="Blue" />
                  <GradientStop Offset="1.0" Color="#CCCCFF" />
                </LinearGradientBrush>
              </GeometryDrawing.Brush>
              <GeometryDrawing.Pen>

                <!-- Outline the drawing with a solid color. -->
                <Pen Thickness="10" Brush="Black" />
              </GeometryDrawing.Pen>
            </GeometryDrawing>
          </DrawingImage.Drawing>
        </DrawingImage>
      </Image.Source>
    </Image>
  </Border>


</Page>

更多代码

如何:使用 PathGeometry 创建形状此示例演示如何使用 PathGeometry 类创建形状。PathGeometry 对象由一个或多个 PathFigure 对象组成;每个 PathFigure 都表示一个不同的“图形”或形状。每个 PathFigure 自身又由一个或多个 PathSegment 对象组成,每个对象均表示图形或形状的已连接部分。线段类型包括 LineSegmentArcSegmentBezierSegment
如何:对 EllipseGeometry 进行动画处理本示例演示如何对 Path 元素内的 Geometry 进行动画处理。在下面的示例中,PointAnimation 用于对 EllipseGeometryCenter 进行动画处理。
如何:使用关键帧对点进行动画处理本示例演示如何使用 PointAnimationUsingKeyFrames 类对 Point 进行动画处理。
如何:创建复合形状 此示例演示如何使用 Geometry 对象创建复合形状并使用 Path 元素显示这些复合形状。在下面的示例中,将 LineGeometryEllipseGeometryRectangleGeometryGeometryGroup 一起使用以创建复合形状。然后,使用 Path 元素绘制这些几何图形。
继承层次结构

System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows..::.Freezable
        System.Windows.Media.Animation..::.Animatable
          System.Windows.Media..::.Geometry
            System.Windows.Media..::.EllipseGeometry
线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.5、3.0
另请参见

参考

其他资源

标记 :


Page view tracker