Skip to content

Invoke button commands through the native click flow - #355

Merged
wieslawsoltes merged 1 commit into
masterfrom
agent/322-invoke-button-click-command
Aug 18, 2026
Merged

wieslawsoltes merged 1 commit into
masterfrom
agent/322-invoke-button-click-command

Conversation

@wieslawsoltes

Copy link
Copy Markdown
Owner

Summary

  • invoke target buttons through Avalonia's native button activation path
  • execute bound commands with their configured command parameters
  • preserve handled Click event, disabled-state, CanExecute, and flyout semantics
  • document the complete behavior and add focused headless tests

Problem

InvokeButtonClickAction previously called button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)). That only raised the routed event. It did not call Button.OnClick(), so Avalonia never reached the command execution portion of its button activation pipeline.

A button with Command="{Binding ...}" therefore appeared to receive a click event while its command was never invoked, which is the failure reported in #322.

Root cause

Avalonia's Button.OnClick() performs more work than raising ClickEvent:

  1. it verifies that the button is effectively enabled
  2. it opens or closes the configured flyout
  3. it raises the routed Click event
  4. if the event was not handled, it evaluates and executes Command with CommandParameter

Raising the routed event directly bypassed steps 1, 2, and 4.

Changes

  • use ButtonAutomationPeer.Invoke() to enter Avalonia's supported button invocation path
  • return false without invoking an effectively disabled target
  • update the API summary and user documentation to describe full button invocation instead of event-only behavior
  • replace the code-behind-oriented documentation example with an MVVM command example

Tests

Added headless coverage proving that:

  • the Click event is raised and the bound command receives the exact configured parameter
  • a handled Click event suppresses command execution, matching Avalonia's native ordering
  • disabled buttons do not raise Click or execute their command

Validation

  • confirmed the command regression test fails against the previous implementation
  • dotnet test tests/Xaml.Behaviors.Interactions.UnitTests/Xaml.Behaviors.Interactions.UnitTests.csproj --filter 'FullyQualifiedName~InvokeButtonClickActionTests' --no-restore
    • 3 passed, 0 failed
  • dotnet test tests/Xaml.Behaviors.Interactions.UnitTests/Xaml.Behaviors.Interactions.UnitTests.csproj --no-restore
    • 92 passed, 0 failed, 2 pre-existing skipped drag tests
  • git diff --check

Closes #322

@wieslawsoltes
wieslawsoltes marked this pull request as ready for review July 14, 2026 22:18
@wieslawsoltes
wieslawsoltes merged commit cacd3ed into master Aug 18, 2026
3 checks passed
@wieslawsoltes
wieslawsoltes deleted the agent/322-invoke-button-click-command branch August 18, 2026 08:30
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.

The InvokeButtonClickAction fails to trigger the button.

1 participant