Skip to content

Extend KeyDownTriggerBehavior with Modifiers and ability to handle already handled events#853

Open
Irina-Konovalova wants to merge 2 commits into
CommunityToolkit:mainfrom
Ecierge:key-down-trigger-behavior-improvements
Open

Extend KeyDownTriggerBehavior with Modifiers and ability to handle already handled events#853
Irina-Konovalova wants to merge 2 commits into
CommunityToolkit:mainfrom
Ecierge:key-down-trigger-behavior-improvements

Conversation

@Irina-Konovalova
Copy link
Copy Markdown

Fixes

This PR extends KeyDownTriggerBehavior.

PR Type

What kind of change does this PR introduce?

  • Other... Please describe: Extend KeyDownTriggerBehavior with Modifiers and ability to handle already handled events.

What is the current behavior?

KeyDownTriggerBehavior does not support modifier keys or PreviewKeyDown, which limits its use in keyboard navigation scenarios.

What is the new behavior?

This PR extends KeyDownTriggerBehavior by adding support for modifier keys, PreviewKeyDown, and handled events. It also updates the XML documentation.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Tested code with current supported SDKs
  • New component
    • Documentation has been added
    • Sample in sample app has been added
    • Analyzers are passing for documentation and samples
    • Icon has been created (if new sample) following the Thumbnail Style Guide and templates
  • Tests for the changes have been added (if applicable)
  • Header has been added to all new source files
  • Contains NO breaking changes

Other information

@Irina-Konovalova Irina-Konovalova force-pushed the key-down-trigger-behavior-improvements branch from 6b836a3 to 8b01b15 Compare May 14, 2026 15:15
@Irina-Konovalova
Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="ECIERGE SOFTWARE DEV INC"

Copy link
Copy Markdown
Member

@Avid29 Avid29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great PR. I love the additional functionality, and I appreciate the coding style such as using guard clauses. However, I dislike the repeated calls to InputKeyboardSource.GetKeyStateForCurrentThread. I do love small purposeful helper functions, but not at the expense of ideal behavior. Let's see about moving the state check into CheckModifiers and inlining IsDown inside Match using the state retrieved in CheckModifiers.

There's also a somewhat trivial code styling question spawned by this PR regarding the ordering of class members. Hoping to get a definitive answer on that soon.

Comment thread components/Behaviors/src/Keyboard/KeyDownTriggerBehavior.cs Outdated
Comment thread components/Behaviors/src/Keyboard/KeyDownTriggerBehavior.cs
- Consolidate modifier state retrieval into CheckModifiers
- Inline IsDown logic into Match
- Remove repeated GetKeyStateForCurrentThread calls
- Update XML documentation to match new signatures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants