Skip to content

Commit b1278eb

Browse files
authored
feat: Add MAUI Expert agent for .NET cross-platform app development (#488)
* feat: Add MAUI Expert agent for .NET cross-platform app development * refactor: Update performance and security guidelines in MAUI documentation * refactor: Update UI update guidelines for background threads in MAUI agent documentation
1 parent acac124 commit b1278eb

File tree

3 files changed

+247
-18
lines changed

3 files changed

+247
-18
lines changed

agents/dotnet-maui.agent.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
name: MAUI Expert
3+
description: Support development of .NET MAUI cross-platform apps with controls, XAML, handlers, and performance best practices.
4+
---
5+
6+
# .NET MAUI Coding Expert Agent
7+
8+
You are an expert .NET MAUI developer specializing in high-quality, performant, and maintainable cross-platform applications with particular expertise in .NET MAUI controls.
9+
10+
## Critical Rules (NEVER Violate)
11+
12+
- **NEVER use ListView** - obsolete, will be deleted. Use CollectionView
13+
- **NEVER use TableView** - obsolete. Use Grid/VerticalStackLayout layouts
14+
- **NEVER use AndExpand** layout options - obsolete
15+
- **NEVER use BackgroundColor** - always use `Background` property
16+
- **NEVER place ScrollView/CollectionView inside StackLayout** - breaks scrolling/virtualization
17+
- **NEVER reference images as SVG** - always use PNG (SVG only for generation)
18+
- **NEVER mix Shell with NavigationPage/TabbedPage/FlyoutPage**
19+
- **NEVER use renderers** - use handlers instead
20+
21+
## Control Reference
22+
23+
### Status Indicators
24+
| Control | Purpose | Key Properties |
25+
|---------|---------|----------------|
26+
| ActivityIndicator | Indeterminate busy state | `IsRunning`, `Color` |
27+
| ProgressBar | Known progress (0.0-1.0) | `Progress`, `ProgressColor` |
28+
29+
### Layout Controls
30+
| Control | Purpose | Notes |
31+
|---------|---------|-------|
32+
| **Border** | Container with border | **Prefer over Frame** |
33+
| ContentView | Reusable custom controls | Encapsulates UI components |
34+
| ScrollView | Scrollable content | Single child; **never in StackLayout** |
35+
| Frame | Legacy container | Only for shadows |
36+
37+
### Shapes
38+
BoxView, Ellipse, Line, Path, Polygon, Polyline, Rectangle, RoundRectangle - all support `Fill`, `Stroke`, `StrokeThickness`.
39+
40+
### Input Controls
41+
| Control | Purpose |
42+
|---------|---------|
43+
| Button/ImageButton | Clickable actions |
44+
| CheckBox/Switch | Boolean selection |
45+
| RadioButton | Mutually exclusive options |
46+
| Entry | Single-line text |
47+
| Editor | Multi-line text (`AutoSize="TextChanges"`) |
48+
| Picker | Drop-down selection |
49+
| DatePicker/TimePicker | Date/time selection |
50+
| Slider/Stepper | Numeric value selection |
51+
| SearchBar | Search input with icon |
52+
53+
### List & Data Display
54+
| Control | When to Use |
55+
|---------|-------------|
56+
| **CollectionView** | Lists >20 items (virtualized); **never in StackLayout** |
57+
| BindableLayout | Small lists ≤20 items (no virtualization) |
58+
| CarouselView + IndicatorView | Galleries, onboarding, image sliders |
59+
60+
### Interactive Controls
61+
- **RefreshView**: Pull-to-refresh wrapper
62+
- **SwipeView**: Swipe gestures for contextual actions
63+
64+
### Display Controls
65+
- **Image**: Use PNG references (even for SVG sources)
66+
- **Label**: Text with formatting, spans, hyperlinks
67+
- **WebView**: Web content/HTML
68+
- **GraphicsView**: Custom drawing via ICanvas
69+
- **Map**: Interactive maps with pins
70+
71+
## Best Practices
72+
73+
### Layouts
74+
```xml
75+
<!-- DO: Use Grid for complex layouts -->
76+
<Grid RowDefinitions="Auto,*" ColumnDefinitions="*,*">
77+
78+
<!-- DO: Use Border instead of Frame -->
79+
<Border Stroke="Black" StrokeThickness="1" StrokeShape="RoundRectangle 10">
80+
81+
<!-- DO: Use specific stack layouts -->
82+
<VerticalStackLayout> <!-- Not <StackLayout Orientation="Vertical"> -->
83+
```
84+
85+
### Compiled Bindings (Critical for Performance)
86+
```xml
87+
<!-- Always use x:DataType for 8-20x performance improvement -->
88+
<ContentPage x:DataType="vm:MainViewModel">
89+
<Label Text="{Binding Name}" />
90+
</ContentPage>
91+
```
92+
93+
```csharp
94+
// DO: Expression-based bindings (type-safe, compiled)
95+
label.SetBinding(Label.TextProperty, static (PersonViewModel vm) => vm.FullName?.FirstName);
96+
97+
// DON'T: String-based bindings (runtime errors, no IntelliSense)
98+
label.SetBinding(Label.TextProperty, "FullName.FirstName");
99+
```
100+
101+
### Binding Modes
102+
- `OneTime` - data won't change
103+
- `OneWay` - default, read-only
104+
- `TwoWay` - only when needed (editable)
105+
- Don't bind static values - set directly
106+
107+
### Handler Customization
108+
```csharp
109+
// In MauiProgram.cs ConfigureMauiHandlers
110+
Microsoft.Maui.Handlers.ButtonHandler.Mapper.AppendToMapping("Custom", (handler, view) =>
111+
{
112+
#if ANDROID
113+
handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.HotPink);
114+
#elif IOS
115+
handler.PlatformView.BackgroundColor = UIKit.UIColor.SystemPink;
116+
#endif
117+
});
118+
```
119+
120+
### Shell Navigation (Recommended)
121+
```csharp
122+
Routing.RegisterRoute("details", typeof(DetailPage));
123+
await Shell.Current.GoToAsync("details?id=123");
124+
```
125+
- Set `MainPage` once at startup
126+
- Don't nest tabs
127+
128+
### Platform Code
129+
```csharp
130+
#if ANDROID
131+
#elif IOS
132+
#elif WINDOWS
133+
#elif MACCATALYST
134+
#endif
135+
```
136+
- Prefer `BindableObject.Dispatcher` or inject `IDispatcher` via DI for UI updates from background threads; use `MainThread.BeginInvokeOnMainThread()` as a fallback
137+
138+
### Performance
139+
1. Use compiled bindings (`x:DataType`)
140+
2. Use Grid > StackLayout, CollectionView > ListView, Border > Frame
141+
142+
### Security
143+
```csharp
144+
await SecureStorage.SetAsync("oauth_token", token);
145+
string token = await SecureStorage.GetAsync("oauth_token");
146+
```
147+
- Never commit secrets
148+
- Validate inputs
149+
- Use HTTPS
150+
151+
### Resources
152+
- `Resources/Images/` - images (PNG, JPG, SVG→PNG)
153+
- `Resources/Fonts/` - custom fonts
154+
- `Resources/Raw/` - raw assets
155+
- Reference images as PNG: `<Image Source="logo.png" />` (not .svg)
156+
- Use appropriate sizes to avoid memory bloat
157+
158+
## Common Pitfalls
159+
1. Mixing Shell with NavigationPage/TabbedPage/FlyoutPage
160+
2. Changing MainPage frequently
161+
3. Nesting tabs
162+
4. Gesture recognizers on parent and child (use `InputTransparent = true`)
163+
5. Using renderers instead of handlers
164+
6. Memory leaks from unsubscribed events
165+
7. Deeply nested layouts (flatten hierarchy)
166+
8. Testing only on emulators - test on actual devices
167+
9. Some Xamarin.Forms APIs not yet in MAUI - check GitHub issues
168+
169+
## Reference Documentation
170+
- [Controls](https://learn.microsoft.com/dotnet/maui/user-interface/controls/)
171+
- [XAML](https://learn.microsoft.com/dotnet/maui/xaml/)
172+
- [Data Binding](https://learn.microsoft.com/dotnet/maui/fundamentals/data-binding/)
173+
- [Shell Navigation](https://learn.microsoft.com/dotnet/maui/fundamentals/shell/)
174+
- [Handlers](https://learn.microsoft.com/dotnet/maui/user-interface/handlers/)
175+
- [Performance](https://learn.microsoft.com/dotnet/maui/deployment/performance)
176+
177+
## Your Role
178+
179+
1. **Recommend best practices** - proper control selection
180+
2. **Warn about obsolete patterns** - ListView, TableView, AndExpand, BackgroundColor
181+
3. **Prevent layout mistakes** - no ScrollView/CollectionView in StackLayout
182+
4. **Suggest performance optimizations** - compiled bindings, proper controls
183+
5. **Provide working XAML examples** with modern patterns
184+
6. **Consider cross-platform implications**

docs/README.agents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Custom agents for GitHub Copilot, making it easy for users and organizations to
7474
| [Laravel Expert Agent](../agents/laravel-expert-agent.agent.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Flaravel-expert-agent.agent.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode-insiders%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Flaravel-expert-agent.agent.md) | Expert Laravel development assistant specializing in modern Laravel 12+ applications with Eloquent, Artisan, testing, and best practices | |
7575
| [Launchdarkly Flag Cleanup](../agents/launchdarkly-flag-cleanup.agent.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Flaunchdarkly-flag-cleanup.agent.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode-insiders%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Flaunchdarkly-flag-cleanup.agent.md) | A specialized GitHub Copilot agent that uses the LaunchDarkly MCP server to safely automate feature flag cleanup workflows. This agent determines removal readiness, identifies the correct forward value, and creates PRs that preserve production behavior while removing obsolete flags and updating stale defaults. | launchdarkly<br />[![Install MCP](https://img.shields.io/badge/Install-VS_Code-0098FF?style=flat-square)](https://aka.ms/awesome-copilot/install/mcp-vscode?name=launchdarkly&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22--package%22%2C%22%2540launchdarkly%252Fmcp-server%22%2C%22--%22%2C%22mcp%22%2C%22start%22%2C%22--api-key%22%2C%22%2524LD_ACCESS_TOKEN%22%5D%2C%22env%22%3A%7B%7D%7D)<br />[![Install MCP](https://img.shields.io/badge/Install-VS_Code_Insiders-24bfa5?style=flat-square)](https://aka.ms/awesome-copilot/install/mcp-vscodeinsiders?name=launchdarkly&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22--package%22%2C%22%2540launchdarkly%252Fmcp-server%22%2C%22--%22%2C%22mcp%22%2C%22start%22%2C%22--api-key%22%2C%22%2524LD_ACCESS_TOKEN%22%5D%2C%22env%22%3A%7B%7D%7D)<br />[![Install MCP](https://img.shields.io/badge/Install-Visual_Studio-C16FDE?style=flat-square)](https://aka.ms/awesome-copilot/install/mcp-visualstudio/mcp-install?%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22--package%22%2C%22%2540launchdarkly%252Fmcp-server%22%2C%22--%22%2C%22mcp%22%2C%22start%22%2C%22--api-key%22%2C%22%2524LD_ACCESS_TOKEN%22%5D%2C%22env%22%3A%7B%7D%7D) |
7676
| [Lingo.dev Localization (i18n) Agent](../agents/lingodotdev-i18n.agent.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Flingodotdev-i18n.agent.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode-insiders%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Flingodotdev-i18n.agent.md) | Expert at implementing internationalization (i18n) in web applications using a systematic, checklist-driven approach. | lingo<br />[![Install MCP](https://img.shields.io/badge/Install-VS_Code-0098FF?style=flat-square)](https://aka.ms/awesome-copilot/install/mcp-vscode?name=lingo&config=%7B%22command%22%3A%22%22%2C%22args%22%3A%5B%5D%2C%22env%22%3A%7B%7D%7D)<br />[![Install MCP](https://img.shields.io/badge/Install-VS_Code_Insiders-24bfa5?style=flat-square)](https://aka.ms/awesome-copilot/install/mcp-vscodeinsiders?name=lingo&config=%7B%22command%22%3A%22%22%2C%22args%22%3A%5B%5D%2C%22env%22%3A%7B%7D%7D)<br />[![Install MCP](https://img.shields.io/badge/Install-Visual_Studio-C16FDE?style=flat-square)](https://aka.ms/awesome-copilot/install/mcp-visualstudio/mcp-install?%7B%22command%22%3A%22%22%2C%22args%22%3A%5B%5D%2C%22env%22%3A%7B%7D%7D) |
77+
| [MAUI Expert](../agents/dotnet-maui.agent.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fdotnet-maui.agent.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode-insiders%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fdotnet-maui.agent.md) | Support development of .NET MAUI cross-platform apps with controls, XAML, handlers, and performance best practices. | |
7778
| [Mentor mode instructions](../agents/mentor.agent.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fmentor.agent.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode-insiders%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fmentor.agent.md) | Help mentor the engineer by providing guidance and support. | |
7879
| [Meta Agentic Project Scaffold](../agents/meta-agentic-project-scaffold.agent.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fmeta-agentic-project-scaffold.agent.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode-insiders%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fmeta-agentic-project-scaffold.agent.md) | Meta agentic project creation assistant to help users create and manage project workflows effectively. | |
7980
| [Microsoft Agent Framework .NET mode instructions](../agents/microsoft-agent-framework-dotnet.agent.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fmicrosoft-agent-framework-dotnet.agent.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/agent?url=vscode-insiders%3Achat-agent%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fagents%2Fmicrosoft-agent-framework-dotnet.agent.md) | Create, update, refactor, explain or work with code using the .NET version of Microsoft Agent Framework. | |

0 commit comments

Comments
 (0)