Procedura: definire un rettangolo utilizzando RectangleGeometry

In questo esempio viene descritto come usare la RectangleGeometry classe per descrivere un rettangolo.

Esempio

Nell'esempio seguente viene illustrato come creare ed eseguire il rendering di un oggetto RectangleGeometry. La posizione relativa e le dimensioni del rettangolo sono definite da una Rect struttura. La posizione relativa è 50,50 e l'altezza e la larghezza creano entrambi 25 un quadrato. L'interno del rettangolo viene dipinto con un LemonChiffon pennello e il relativo contorno viene dipinto con un Black tratto con uno spessore di 1.

<Path Fill="LemonChiffon" Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <RectangleGeometry Rect="50,50,25,25" />
  </Path.Data>
</Path>
RectangleGeometry myRectangleGeometry = new RectangleGeometry();
myRectangleGeometry.Rect = new Rect(50,50,25,25);

Path myPath = new Path();
myPath.Fill = Brushes.LemonChiffon;
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myRectangleGeometry;
Dim myRectangleGeometry As New RectangleGeometry()
myRectangleGeometry.Rect = New Rect(50,50,25,25)

Dim myPath As New Path()
myPath.Fill = Brushes.LemonChiffon
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myRectangleGeometry

A RectangleGeometry
RectangleGeometry

Anche se in questo esempio è stato usato un Path elemento per eseguire il rendering di RectangleGeometry, esistono molti altri modi per usare RectangleGeometry gli oggetti. Ad esempio, un RectangleGeometry oggetto può essere usato per specificare l'oggetto Clip di un UIElement oggetto o Geometry di un oggetto GeometryDrawing.

Altre classi geometry semplici includono LineGeometry e EllipseGeometry. Queste geometrie, oltre a quelle più complesse, possono essere create anche usando un PathGeometry oggetto o StreamGeometry.

Vedi anche