Skip to content

ComboBox resets selected item to the first one on Esc key press when the drop-down is closed #10767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kirill-zakharov-altium opened this issue Apr 14, 2025 · 5 comments
Labels
Investigate Requires further investigation by the WPF team.

Comments

@kirill-zakharov-altium
Copy link

kirill-zakharov-altium commented Apr 14, 2025

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

@miloush
Copy link
Contributor

miloush commented Apr 14, 2025

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?

@kirill-zakharov-altium
Copy link
Author

@miloush hello,

  • I added the repro projects: ComboBoxTest.zip.
  • No, in .NET FW nothing happens on the Esc key press.

@miloush
Copy link
Contributor

miloush commented Apr 14, 2025

Ah, interesting, it performs text search with \u001B

@miloush
Copy link
Contributor

miloush commented Apr 14, 2025

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.

@kirill-zakharov-altium
Copy link
Author

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.

@siagupta0202 siagupta0202 added the Investigate Requires further investigation by the WPF team. label Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

3 participants