Skip to content

Commit 62a3ce0

Browse files
docs(skill): add Canvas recipe, document name collision workaround (#292)
* docs(skill): add Canvas recipe, document name collision The Canvas() factory shadows Canvas.SetLeft(). Document the correct Reactor pattern: use .Canvas(left, top) fluent modifier instead. Add complete Canvas recipe with positioning examples. Fixes #282 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor: move Canvas recipe out of getting-started Create canvas-positioning.cs recipe in reactor-recipes and remove inline Canvas section from getting-started SKILL.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 63216ae commit 62a3ce0

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

plugins/reactor/skills/reactor-recipes/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The full recipe content is in `references/<name>.cs`. Read just the recipe(s) th
1818
| Form with validation + submit gating | `references/form-with-validation.cs` | `UseValidationContext`, `FormField`, `Validate.*`, `ShowWhen` |
1919
| Fetch data with loading / error / data states | `references/async-fetch-list.cs` | `UseResource`, `AsyncValue<T>.Match` |
2020
| Themed Win11 card surface | `references/themed-card.cs` | `Theme.*` tokens, `Border`, `FlexColumn`, `.Padding`, `.CornerRadius`, `.WithBorder` |
21+
| Absolute positioning with Canvas | `references/canvas-positioning.cs` | `Canvas`, `.Canvas(left, top)`, `.CenterAt`, shapes |
2122

2223
See `references/index.md` for the full index.
2324

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Recipe: absolute positioning with Canvas.
2+
//
3+
// Pattern: Canvas() factory + .Canvas(left, top) modifier on children.
4+
// ⚠️ `using static Factories` brings a Canvas() factory that shadows
5+
// Microsoft.UI.Xaml.Controls.Canvas — do NOT call Canvas.SetLeft()/SetTop(),
6+
// use the fluent .Canvas(left, top) modifier instead.
7+
8+
// In this clone, run `mur pack-local` once. Bump the version below to match
9+
// whatever `mur pack-local` printed (default: 0.0.0-local). For a real NuGet
10+
// consumer, set Version to a published Microsoft.UI.Reactor release.
11+
#:package Microsoft.UI.Reactor@0.0.0-local
12+
#:package Microsoft.WindowsAppSDK@2.0.1
13+
#:property OutputType=WinExe
14+
#:property TargetFramework=net10.0-windows10.0.22621.0
15+
#:property UseWinUI=true
16+
#:property WindowsPackageType=None
17+
18+
using Microsoft.UI.Reactor;
19+
using Microsoft.UI.Reactor.Core;
20+
using Microsoft.UI.Xaml;
21+
using static Microsoft.UI.Reactor.Factories;
22+
23+
ReactorApp.Run<App>("Canvas demo", width: 600, height: 500);
24+
25+
class App : Component
26+
{
27+
public override Element Render()
28+
{
29+
return Canvas(
30+
// Position children with the .Canvas(left, top) extension
31+
Border(TextBlock("A").Padding(8))
32+
.Background(Theme.CardBackground)
33+
.WithBorder(Theme.CardStroke, 1)
34+
.CornerRadius(4)
35+
.Canvas(left: 50, top: 30),
36+
37+
Border(TextBlock("B").Padding(8))
38+
.Background(Theme.CardBackground)
39+
.WithBorder(Theme.CardStroke, 1)
40+
.CornerRadius(4)
41+
.Canvas(left: 200, top: 100),
42+
43+
// Center on a point (anchor 0.5, 0.5)
44+
Ellipse().Width(20).Height(20)
45+
.Fill(Theme.Accent)
46+
.CenterAt(x: 150, y: 75),
47+
48+
// Shapes
49+
Line(50, 55, 200, 125).Stroke(Theme.DividerStroke, 1),
50+
Rectangle().Width(60).Height(40)
51+
.Fill(Theme.SubtleFill)
52+
.Canvas(left: 350, top: 50)
53+
) with { Width = 500, Height = 400, Background = Theme.SolidBackground };
54+
}
55+
}

plugins/reactor/skills/reactor-recipes/references/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ component.
2222
| Form with validation + submit | [`form-with-validation.cs`](form-with-validation.cs) | `UseValidationContext`, `FormField`, `Validate.*` |
2323
| Fetch data, show loading / error | [`async-fetch-list.cs`](async-fetch-list.cs) | `UseResource`, `AsyncValue<T>.Match` |
2424
| Themed card with 4px grid spacing | [`themed-card.cs`](themed-card.cs) | `Theme.*`, `Border`, `FlexColumn`, `.Padding`, `.CornerRadius` |
25+
| Absolute positioning with Canvas | [`canvas-positioning.cs`](canvas-positioning.cs) | `Canvas`, `.Canvas(left, top)`, `.CenterAt`, shapes |
2526

2627
## How to use a recipe
2728

0 commit comments

Comments
 (0)