Skip to content

Why do Wpf TextBoxes only mark some Events as Handled #10138

@PxC-MKias

Description

@PxC-MKias

Description

I work on some Interaction Detection and use the fact that Controls mark RoutedEvents as Handled when they handle them.
Unfortunately, TextBoxes only mark TextCompositionEventArgs in the OnTextInput method and ExecutedRoutedEventArgs in the OnSpace as Handled (see TextEditorTyping.cs#L386). All other Events (Delete, Key Events, ...) that are also implemented in TextEditorTyping are not marked as handled. Is there a Reason for that? It is a problem for my usecase.

Reproduction Steps

Register a ClassHandler for handled Events and debug what Controls handle the events.

KeyEventHandler keyEventHandler = /* please ask for the implementation if its necessary */
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.PreviewKeyDownEvent, keyEventHandler, true);
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.KeyDownEvent, keyEventHandler, true);
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.PreviewKeyUpEvent, keyEventHandler, true);
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.KeyUpEvent, keyEventHandler, true);

Expected behavior

TextBoxes handle all Events that change its text.

Actual behavior

TextBoxes only mark TextCompositionEventArgs in the OnTestInput method and ExecutedRoutedEventArgs in the OnSpace as Handled.
All common KeyEvents do not mark events as Handled, as well as all other event handling methods OnBackspace, OnDelete, OnToggleInsert, ...

TextEditorTyping.cs#L386

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

Not configuration specific as far as I know, but the target framework is net80-windows

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionGeneral question, not a problem in source code or documentation (yet)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions