Skip to content

[WIP] Add trimmable EventTrigger for AOT safety#34012

Closed
Copilot wants to merge 13 commits into
fix/33591-eventtrigger-aotfrom
copilot/sub-pr-33611
Closed

[WIP] Add trimmable EventTrigger for AOT safety#34012
Copilot wants to merge 13 commits into
fix/33591-eventtrigger-aotfrom
copilot/sub-pr-33611

Conversation

Copilot AI commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Rebase Plan for EventTrigger AOT PR

The original PR branch has a grafted commit that prevents clean rebasing. I will:

  • Understand the issue and fetch required branches
  • Reset current branch to net11.0 base
  • Cherry-pick EventTrigger implementation files from original PR
  • Resolve diagnostic ID conflicts (MAUIX2007 → MAUIX2014)
  • Merge resource strings for net11.0 compatibility
  • Update AnalyzerReleases.Unshipped.md
  • Verify SourceGen project builds
  • Fix source generator integration and run targeted tests
  • Final validation and completion

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

simonrozsival and others added 13 commits January 20, 2026 14:31
Introduce EventTrigger.Create<T>() factory methods that use static lambdas
instead of reflection-based event subscription. The XAML SourceGen now emits
calls to these factory methods for AOT compatibility.

Architecture:
- Single EventTrigger class with internal strategy pattern
- ReflectionStrategy for backward compat (annotated with RUC/RDC)
- StaticStrategy<T> for AOT-safe event subscription
- No new public types - strategies are private nested classes

Backward compatibility:
- Existing new EventTrigger() constructor still works
- EventTrigger.Event property is still set by SourceGen
- All existing XAML works unchanged

Fixes #33591
The SourceGen was generating both 'new EventTrigger()' and
'EventTrigger.Create<T>()' for the same EventTrigger, resulting
in dead code. This change defers EventTrigger creation from
CreateValuesVisitor to SetPropertiesVisitor when the Event
property is present, allowing the factory method to be used
directly.

Changes:
- EventTriggerValueProvider now marks EventTrigger nodes for
  deferred creation instead of skipping them entirely
- CreateValuesVisitor registers variable names for deferred
  EventTriggers without emitting creation code
- SetEventTriggerEvent emits the full variable declaration
  with the factory call
- Added DeferredEventTriggers set to SourceGenContext to track
  nodes that need deferred creation
- Updated Maui33591SourceGenTests snapshot to verify clean output
Move EventTrigger declaration to CreateValuesVisitor to fix variable ordering.
EventTrigger children (TriggerActions) need the variable declared before they're
processed in SetPropertiesVisitor (which uses bottom-up order).

Key changes:
- CreateValuesVisitor: Emit EventTrigger.Create<T>() call directly by walking up
  the XAML tree to find the target type
- EventTriggerValueProvider: Simplified to just return existing variable name
- EventTrigger.Create: Added eventName parameter for cleaner one-line generation
- Updated snapshot test to match new output
Consolidate EventTrigger-specific code in one place:
- Add EmitDeclaration static method with all generation logic
- Add FindTargetType helper method
- CreateValuesVisitor now just calls EmitDeclaration
- CreateValuesVisitor registers the variable name
- GenerateCreateInstanceCall generates the Create<T>() or new EventTrigger() call
- Cleaner separation of concerns
CreateValuesVisitor: writer.Write($"var {varName} = ");
EventTriggerValueProvider: writer.WriteLine("EventTrigger.Create<...>(...);")
Address review feedback: use pattern matching instead of direct cast
to gracefully handle incompatible types at runtime.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants