maui-graphics-drawing
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "maui-graphics-drawing" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-222bd6a114e2d1723c99bbe25f98cb6e09053f0040bda51495f008a67be0ea20. Verify the upstream source and version against https://github.com/davidortinau/maui-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Guidance for custom drawing using Microsoft.Maui.Graphics, covering GraphicsView and canvas drawing operations, shape drawing, path drawing, text rendering, image drawing, shadow effects, clipping, and canvas state management. Applicable to “custom drawing”, “GraphicsView”, “canvas drawing”, “drawing shapes”, “drawing paths”, “drawing text”, “ICanvas”, “IDrawable”, “shadows”, “clipping”, “Microsoft.Maui.Graphics”. Not applicable to view animations (use maui-animations), touch gesture handling for drawn elements (use maui-gestures), or app icons (use maui-app-icons-splash).
Introduction source: third_party · davidortinau · 0.0.1 Reference
SkillPi interpretation
- Tasks
- ⚠️ Unpaired `SaveState`/`RestoreState` causes state leaks across draw calls.
- Testing
- Not tested
Browse files
Frontmatter
name: maui-graphics-drawing
description: >
Guidance for custom drawing with Microsoft.Maui.Graphics, GraphicsView, canvas drawing operations,
shapes, paths, text rendering, image drawing, shadows, clipping, and canvas state management.
USE FOR: "custom drawing", "GraphicsView", "canvas drawing", "draw shapes", "draw path",
"draw text", "ICanvas", "IDrawable", "shadows", "clipping", "Microsoft.Maui.Graphics".
DO NOT USE FOR: view animations (use maui-animations), gesture handling on drawn elements
(use maui-gestures), or app icons (use maui-app-icons-splash)..NET MAUI Graphics Drawing
Common gotchas
| Issue | Fix |
|---|---|
| Nothing draws on screen | Ensure Drawable is set on GraphicsView and the control has non-zero HeightRequest/WidthRequest |
| State bleeds between shapes | Wrap isolated sections in SaveState() / RestoreState() pairs |
| Shadows stick to later draws | Call canvas.SetShadow(SizeF.Zero, 0, null) after drawing the shadowed element |
| Clipping never resets | Clipping is cumulative per frame — use SaveState/RestoreState around clip regions |
| UI freezes during drawing | Never do I/O, network, or heavy computation inside Draw() — it runs on the UI thread |
Canvas state — always pair Save/Restore
⚠️ Unpaired SaveState/RestoreState causes state leaks across draw calls.
// ✅ Correct — isolated state
canvas.SaveState();
canvas.StrokeColor = Colors.Red;
canvas.StrokeSize = 6;
canvas.DrawRectangle(10, 10, 80, 80);
canvas.RestoreState();
// Stroke reverts to previous values
// ❌ Wrong — state leaks to everything drawn after
canvas.StrokeColor = Colors.Red;
canvas.StrokeSize = 6;
canvas.DrawRectangle(10, 10, 80, 80);
// Every subsequent shape is now red with size 6
Saves/restores: stroke, fill, font, shadow, clip, and transforms. Nest calls for layered isolation.
Triggering redraws
// ✅ Correct — queue a redraw
graphicsView.Invalidate();
// ❌ Wrong — never call Draw() directly
myDrawable.Draw(canvas, rect);
Invalidate()queues a redraw; the framework callsIDrawable.Drawon the next frame.- ⚠️ Avoid calling
Invalidate()in a tight loop — batch state changes, then invalidate once.
Performance tips
- Keep
Draw()fast — pre-compute paths and data outside the draw method;Draw()is called on every frame. - Reuse
PathFobjects — create them once, store as fields, draw repeatedly. - Use
MeasureFirstItem-style thinking — if drawing many identical items, calculate dimensions once. - Minimize allocations — avoid
new PathF()insideDraw()when the path doesn't change.
// ✅ Pre-computed path (field)
private readonly PathF _starPath = BuildStarPath();
public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.FillPath(_starPath);
}
// ❌ Allocating every frame
public void Draw(ICanvas canvas, RectF dirtyRect)
{
var path = new PathF();
// ...build path every frame...
canvas.FillPath(path);
}
Shadows and clipping — sticky state pitfalls
Shadows apply to all subsequent draws until explicitly removed. Clips accumulate and can only be undone with RestoreState():
// ✅ Shadow: remove after use
canvas.SetShadow(new SizeF(5, 5), 4, Colors.Gray);
canvas.FillRectangle(20, 20, 100, 60);
canvas.SetShadow(SizeF.Zero, 0, null); // ← must remove
// ✅ Clip: isolate with SaveState/RestoreState
canvas.SaveState();
canvas.ClipRectangle(20, 20, 100, 100);
canvas.FillRectangle(0, 0, 200, 200); // clipped
canvas.RestoreState(); // clip removed
// ❌ Clip persists — everything after is also clipped
canvas.ClipRectangle(20, 20, 100, 100);
canvas.FillEllipse(150, 150, 50, 50); // unintentionally clipped!
Set properties BEFORE draw calls
// ✅ Properties then draw
canvas.StrokeColor = Colors.Blue;
canvas.DrawRectangle(10, 10, 100, 50);
// ❌ Setting after draw has no effect on previous shape
canvas.DrawRectangle(10, 10, 100, 50);
canvas.StrokeColor = Colors.Blue;
Decision framework
| Need | Approach |
|---|---|
| Simple shapes / static graphics | Single IDrawable, draw in Draw() |
| Animated graphics | Update state externally, call Invalidate() from timer/animation |
| Complex layered scene | Multiple SaveState/RestoreState blocks, or separate drawables |
| Hit testing on drawn elements | Track shape bounds manually — GraphicsView has no built-in hit test on drawn content |
| Platform-specific rendering | Use handlers/platform code; Microsoft.Maui.Graphics is cross-platform only |
Quick checklist
- [ ]
GraphicsViewhasDrawableset and non-zero size - [ ]
Draw()is fast — no I/O, no heavy allocations - [ ] Every
SaveState()has a matchingRestoreState() - [ ] Shadows removed with
SetShadow(SizeF.Zero, 0, null)after use - [ ] Clips wrapped in
SaveState/RestoreStateblocks - [ ] Properties set before the draw call they apply to
- [ ]
Invalidate()used instead of callingDraw()directly
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 .NET MAUI Graphics 绘图的实质性技术指导
- 覆盖常见陷阱和性能优化建议
- 面向开发者解决实际绘图问题
Highlights
- 触发词覆盖完整且边界清晰
- 明确区分适用和不适用场景
- 技术术语准确
Highlights
- 章节结构清晰完整
- 包含代码示例和决策框架
- 提供实用的检查清单
Highlights
- 代码示例语法正确
- 覆盖主要异常情况和最佳实践
- 提供完整的避坑指南
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.