Skip to content

Support bound Flyout opened and closed events - #368

Merged
wieslawsoltes merged 2 commits into
masterfrom
agent/350-flyout-events
Aug 19, 2026
Merged

wieslawsoltes merged 2 commits into
masterfrom
agent/350-flyout-events

Conversation

@wieslawsoltes

Copy link
Copy Markdown
Owner

Summary

  • make EventTriggerBehavior observe Flyout.Opened and Flyout.Closed through strongly typed subscriptions
  • synchronize Flyout-attached behaviors and actions with the placement target's logical/data-context scope
  • preserve compiled command bindings when the Flyout is hosted outside the normal logical tree
  • document the direct Flyout usage and add an end-to-end headless regression

Root cause

Avalonia 12's FlyoutBase derives from AvaloniaObject, not StyledElement. A behavior attached directly to a Flyout could register the requested CLR event through the reflection fallback, but it had no logical parent or inherited data context. Consequently, InvokeCommandAction.Command="{Binding ...}" remained unresolved and made the event appear not to fire.

The generic reflection path was also unnecessary for the two known Flyout lifecycle events.

Changes

  • register Opened and Closed in AddEventHandlerRegistry through a focused FlyoutEventHandler
  • avoid adding any new reflection and make these event paths trimming/AOT friendly
  • observe FlyoutBase.TargetProperty
  • when a placement target is assigned:
    • attach the behavior/action logical scope to that target
    • mirror the target's data context
    • update both when a Flyout is reused with another target
  • dispose target and data-context subscriptions when the behavior detaches
  • allow trigger actions to attach whenever their behavior has a valid logical parent
  • document Flyout lifecycle event usage

Tests

A compiled-XAML headless fixture matches the reported pattern:

  • behaviors are attached directly to a Flyout
  • Opened and Closed each invoke a compiled-bound command exactly once
  • the command binding comes from the placement button/window data context
  • PassEventArgsToCommand receives the original event argument

Validation

  • focused EventTriggerBehaviorTests: 5 passed
  • Xaml.Behaviors.Interactivity.UnitTests: 93 passed
  • Xaml.Behaviors.Interactions.UnitTests: 90 passed, 2 pre-existing skipped
  • git diff --check: clean

Closes #350

@wieslawsoltes
wieslawsoltes merged commit 2879042 into master Aug 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flyout Opened/Closed events not triggered with EventTriggerBehavior in Xaml.Behaviors v12

1 participant