dotnet / dotnet/wpf

Why do Wpf TextBoxes only mark some Events as Handled

Open
#10,138 4 comments 1 reaction 0 assignees View on GitHub
Question
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### 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](https://github.com/dotnet/wpf/blob/227c5cfddb3b6098d56706c1c22161d1b6dbe88c/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/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](https://github.com/dotnet/wpf/blob/227c5cfddb3b6098d56706c1c22161d1b6dbe88c/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.