wpf
wpf copied to clipboard
ComboBox resets selected item to the first one on Esc key press when the drop-down is closed
Description
If you focus a ComboBox and press the Esc key, it resets the selected item to the first one. It happens when the ComboBox's drop-down is closed. In the .NET Framework 4.8, it didn't happen.
See the video: https://github.com/user-attachments/assets/5db212dd-2d89-4fe1-b00d-07d23ace75f0
Here are the repro projects: ComboBoxTest.zip
Reproduction Steps
- Create a new WPF project in .NET6,8,9 (the bug is reproducible in all 3 versions)
- Add the following code into the MainWindow.xaml into the root Window tag:
<ComboBox
Width="100"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SelectedIndex="0">
<ComboBox.Items>
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>3</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
- Run the project, click on the combo-box, click on the 3rd item in the drop-down, and then press the Esc key (when the drop-down is closed).
Expected behavior
The selected item must not be changed on the Esc key press and must remain "3". That's how it worked in .NET Framework 4.8.
Actual behavior
The selected item is reset to "1" after the Esc key press. That's very counterintuitive.
Regression?
It's a regression to the .NET Framework 4.8 version.
Known Workarounds
No response
Impact
No response
Configuration
No response
Other information
No response
It would be helpful to include the repro project. I noticed in the video that the .NET 6 combo box is focused after pressing Esc. Does the .NET FW exhibit the same behavior when you focus it first and then hit Esc?
@miloush hello,
- I added the repro projects: ComboBoxTest.zip.
- No, in .NET FW nothing happens on the Esc key press.
Ah, interesting, it performs text search with \u001B
Right, so it boils down to whether "1".StartsWith("\u001B"). Unfortunately the .NET Core switched to ICU, so the default behavior changed. This is documented here: https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-icu
If switching back to NLS is an option for your application, that would be an easy fix.
Thank you, @miloush. As for me, it looks like an acceptable workaround. Our project is for Windows only, and who knows, maybe if we fallback to NLS we'll avoid some other yet unknown issues caused by transitioning to ICU. Anyway, I hope that this bug will be properly fixed in the platform.