-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
- .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use
dotnet --info) 6.0.100-preview.6.21355.2 - Windows version: (
winver) 21H1 - Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
- Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No, ComboBox
- Security issues and bugs should be reported privately, learn more via our responsible disclosure guidelines.
Problem description:
When first loading a ComboBox, you can use the keyboard to tab to it and arrow-key to ComboBoxItems.
The problem is you can select disabled (IsEnabled=False) items as well.
Once you open the Dropdown (expand it by clicking it), it shows disabled items in the correct theme, and they cannot be selected.
From this point, the keyboard can no longer select them either.
I found a very old blog post that mentioned this as a bug, so wanted to see if it is still a bug, or if there's a better way to handle such a thing today.
https://elgaard.blog/2009/09/03/wpf-making-combo-box-items-disabled-also-when-accessed-using-the-keyboard/
Actual behavior:
First visit to a ComboBox via Keyboard allows selection of disabled ComboBoxItems.
Here's the keyboard navigation to the null / Separator item:

After expanding the dropdown via mouse:

Expected behavior:
Shouldn't be able to select a disabled item via keyboard.
Minimal repro:
Bind to a MyItems collection with a null value (I tested with List<string>).
<ComboBox x:Name="cmbTester" ItemsSource="{Binding MyItems}" MinWidth="150" IsEditable="False"
IsReadOnly="True" IsTextSearchEnabled="False">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding Mode=OneWay}" Value="{x:Null}">
<Setter Property="IsEnabled" Value="False"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
Alternatively, use the NuGet repro for the bug I'm investigating: NuGet/Home#11007