maui-graphics-drawing

Guide Microsoft.Maui.Graphics custom drawings with SaveState/RestoreState and Invalidate.

Updated Nov 27, 2025
One-click install
npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-graphics-drawing-seydakaratekeli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: maui-graphics-drawing
Source: https://github.com/seydakaratekeli/KamPay3/tree/main/KamPay/.github/skills/maui-graphics-drawing%20-%20Kopyala
Command: npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-graphics-drawing-seydakaratekeli

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Helps developers avoid common rendering and state-management pitfalls when creating custom canvas graphics with Microsoft.Maui.Graphics; addresses invisible drawings, state bleeding between shapes, persistent shadows, cumulative clipping, and UI freezes during draw calls.

Core Features & Use Cases

  • Correct canvas state management: Emphasizes always pairing SaveState() and RestoreState() to prevent style and clip leakage.
  • Shadow and clipping guidance: Explains removing shadows after use and isolating clips to avoid visual artifacts.
  • Performance and reuse: Recommends precomputing PathF objects, minimizing allocations, and invalidating the GraphicsView instead of calling Draw directly.
  • Use Case: Implement a custom IDrawable for a dashboard widget that draws complex repeated shapes with shadows and text while remaining responsive and platform-consistent.

Quick Start

Implement an IDrawable for your GraphicsView, set canvas properties before drawing, wrap clips and shadows in SaveState/RestoreState pairs, precompute reusable PathF objects, and call graphicsView.Invalidate() to refresh the view.

Frequently Asked Questions about maui-graphics-drawing

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

FAQPage Schema
Why do my .NET MAUI GraphicsView drawings show invisible shapes or state bleeding between canvas elements?

Persistent shadows and cumulative clipping in Microsoft.Maui.Graphics happen when shadows are not explicitly removed after use. Clear shadows by calling SetShadow(SizeF.Zero, 0, null) and isolate clips within SaveState and RestoreState pairs to prevent visual artifacts.

How do I trigger a redraw of a custom IDrawable in .NET MAUI without freezing the UI?

To trigger a redraw of a custom IDrawable in .NET MAUI, call graphicsView.Invalidate() instead of invoking the Draw method directly. This refreshes the canvas rendering safely without causing UI freezes during state changes or timer-driven animations.

What is the best way to optimize Microsoft.Maui.Graphics performance for repeated shapes and paths?

Optimizing Microsoft.Maui.Graphics performance requires precomputing reusable PathF objects and minimizing allocations within the draw cycle. Set all canvas properties before issuing draw calls and invalidate the GraphicsView to refresh complex repeated shapes efficiently.

Does this guidance for custom canvas drawing apply to dashboard widgets with text and shadows in .NET MAUI?

Yes, this guidance applies to building responsive .NET MAUI dashboard widgets that render complex repeated shapes, text, and shadows. By pairing SaveState and RestoreState and precomputing paths, widgets remain platform-consistent and responsive.

Can I use external timers to drive GraphicsView animations in .NET MAUI without causing state leaks?

Yes, you can drive GraphicsView animations with external timers in .NET MAUI without state leaks by calling graphicsView.Invalidate() on state changes. Always pair SaveState and RestoreState to ensure canvas properties do not bleed between animation frames.