creating-graphics-in-code

Creates WPF graphics programmatically in C# using Shape, PathGeometry, and StreamGeometry classes.

Updated Nov 22, 2023
One-click install
npx skills add https://github.com/parksanghoon-sys/TestCode --skill creating-graphics-in-code-parksanghoon-sys
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: creating-graphics-in-code
Source: https://github.com/parksanghoon-sys/TestCode/tree/main/src/Modbus/wpf-dev-pack/.agents/skills/creating-graphics-in-code
Command: npx skills add https://github.com/parksanghoon-sys/TestCode --skill creating-graphics-in-code-parksanghoon-sys

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building charts, diagrams, or procedurally generated visuals in WPF often requires creating shapes and geometry dynamically in C# code rather than static XAML, which involves verbose PathFigure and segment APIs that are easy to get wrong. ## Core Features & Use Cases - Shape Factory Pattern: Generate Ellipse, Rectangle, and Line elements with configurable fills, strokes, and corner radii for dynamic Canvas content. - Geometry Builder Pattern: Construct polygons, polylines, Bezier curves, and arcs using PathGeometry, PathFigure, and segment classes, plus composite arrows with computed heads. - Performance Optimization: Use StreamGeometry with Freeze() for static complex shapes, with guidance on when to choose Shape, PathGeometry, StreamGeometry, or DrawingVisual. - Use Case: When rendering a data plot, generate circle markers for each data point, connect them with a polyline Path, and add everything to a Canvas at runtime. ## Quick Start Ask the AI to generate C# code that draws a polygon and connecting line chart on a WPF Canvas using PathGeometry and Shape classes.

Frequently Asked Questions about creating-graphics-in-code

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a PathGeometry with segments programmatically in WPF C#?▼

Create a PathFigure with a StartPoint, add LineSegment, BezierSegment, or ArcSegment objects to its Segments collection, then add the figure to a PathGeometry. Assign the geometry to a Path element's Data property to render it.

How to draw shapes dynamically and add them to a WPF Canvas?▼

Instantiate Ellipse, Rectangle, or Line objects in C#, set their Fill and Stroke properties, position them with Canvas.SetLeft and Canvas.SetTop, then add them to the Canvas.Children collection.

What is the difference between PathGeometry and StreamGeometry in WPF?▼

StreamGeometry is lighter and faster for static complex shapes because it is immutable after construction, while PathGeometry supports data binding and modification. Call Freeze() on StreamGeometry to maximize rendering performance.

When should I use DrawingVisual instead of Shape in WPF?▼

Use DrawingVisual for large datasets requiring the highest rendering performance, since it skips layout and data binding overhead. Use Shape-derived classes when elements need interactivity, input handling, or layout participation.

Why should I call Freeze on WPF geometry and brushes?▼

Freeze makes freezable objects immutable and thread-safe, which improves rendering performance for static graphics. Unfrozen objects incur change-tracking overhead on every render pass.