[WIP] Add trimmable EventTrigger for AOT safety#34012
Closed
Copilot wants to merge 13 commits into
Closed
Conversation
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.
…zer release tracking
Copilot stopped work on behalf of
simonrozsival due to an error
February 12, 2026 10:02
Copilot stopped work on behalf of
simonrozsival due to an error
February 12, 2026 11:55
f07cb44 to
6afe2be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebase Plan for EventTrigger AOT PR
The original PR branch has a grafted commit that prevents clean rebasing. I will:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.