Creates WPF graphics dynamically in C# code using Shape, PathGeometry, and PathFigure classes. Use when building charts, diagrams, or procedurally generated graphics.
View on GitHubchristian289/dotnet-with-claudecode
wpf-dev-pack
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/christian289/dotnet-with-claudecode/blob/main/wpf-dev-pack/skills/creating-graphics-in-code/SKILL.md -a claude-code --skill creating-graphics-in-codeInstallation paths:
.claude/skills/creating-graphics-in-code/# Creating WPF Graphics in Code
Programmatically create shapes and geometry for dynamic graphics.
## 1. Shape Factory Pattern
```csharp
namespace MyApp.Graphics;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
public static class ShapeFactory
{
/// <summary>
/// Create circular marker
/// </summary>
public static Ellipse CreateCircle(double size, Brush fill, Brush? stroke = null)
{
var ellipse = new Ellipse
{
Width = size,
Height = size,
Fill = fill
};
if (stroke is not null)
{
ellipse.Stroke = stroke;
ellipse.StrokeThickness = 1;
}
return ellipse;
}
/// <summary>
/// Create rectangle with optional corner radius
/// </summary>
public static Rectangle CreateRectangle(
double width,
double height,
Brush fill,
double cornerRadius = 0)
{
return new Rectangle
{
Width = width,
Height = height,
Fill = fill,
RadiusX = cornerRadius,
RadiusY = cornerRadius
};
}
/// <summary>
/// Create line between two points
/// </summary>
public static Line CreateLine(Point start, Point end, Brush stroke, double thickness = 1)
{
return new Line
{
X1 = start.X,
Y1 = start.Y,
X2 = end.X,
Y2 = end.Y,
Stroke = stroke,
StrokeThickness = thickness
};
}
}
```
---
## 2. Geometry Builder Pattern
```csharp
namespace MyApp.Graphics;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
public static class GeometryBuilder
{
/// <summary>
/// Create polygon from points
/// </summary>
public static PathGeometry CreatePolygon(IReadOnlyList<Point> points)
{
if (points.Count < 3)
return new PathGeometr