Files
docs-desktop/dotnet-desktop-guide/framework/wpf/graphics-multimedia/how-to-create-a-shape-using-a-streamgeometry.md
T
Pooja PoojariandAndy De George 6d665a13bd US-1889327: Updated H2 headings. (#1323)
* Updated H2 headings for US-1889327.

* Review edits.

* Apply suggestions from code review

Co-authored-by: Andy (Steve) De George <[email protected]>
2022-03-04 18:48:05 +00:00

3.3 KiB

title, description, ms.date, ms.custom, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date ms.custom dev_langs helpviewer_keywords ms.assetid
How to: Create a Shape Using a StreamGeometry Learn how to create a Shape using a StreamGeometry. 03/30/2017 devdivchpfy22
csharp
vb
graphics [WPF], shapes
shapes [WPF], creating with StreamGeometry class
08f7c8ce-074b-49cd-9aba-cc9592d4ee51

How to: Create a Shape Using a StreamGeometry

xref:System.Windows.Media.StreamGeometry is lightweight alternative to xref:System.Windows.Media.PathGeometry for creating geometric shapes. Use a xref:System.Windows.Media.StreamGeometry when you need to describe a complex geometry but do not want the overhead of supporting data binding, animation, or modification. For example, because of its efficiency, the xref:System.Windows.Media.StreamGeometry class is a good choice for describing adorners.

Create a triangular StreamGeometry

The following example uses attribute syntax to create a triangular xref:System.Windows.Media.StreamGeometry in [!INCLUDETLA2#tla_xaml].

[!code-xamlGeometriesMiscSnippets_snip#StreamGeometryTriangleExampleWholePage]

For more information about xref:System.Windows.Media.StreamGeometry attribute syntax, see the Path Markup Syntax page.

Use a StreamGeometry to define a triangle

The next example uses a xref:System.Windows.Media.StreamGeometry to define a triangle in code. First, the example creates a xref:System.Windows.Media.StreamGeometry, then obtains a xref:System.Windows.Media.StreamGeometryContext and uses it to describe the triangle.

[!code-csharpGeometriesMiscSnippets_procedural_snip#StreamGeometryTriangleExampleWholePage] [!code-vbGeometriesMiscSnippets_procedural_snip#StreamGeometryTriangleExampleWholePage]

Create a geometric shape in code

The next example creates a method that uses a xref:System.Windows.Media.StreamGeometry and xref:System.Windows.Media.StreamGeometryContext to define a geometric shape based on specified parameters.

[!code-csharpGeometriesMiscSnippets_procedural_snip#StreamGeometryExampleWholePage] [!code-vbGeometriesMiscSnippets_procedural_snip#StreamGeometryExampleWholePage]

See also