How to make WPF ComboBox keyboard text search work correctly if IsEditable and IsReadOnly are true?

Hi everyone, I have a problem with WPF ComboBox, look at the code

<ComboBox x:Name="comboBox" Width="100" IsReadOnly="True" IsEditable="True" IsTextSearchEnabled="True"> <ComboBoxItem>dsf gd</ComboBoxItem> <ComboBoxItem>asf gd</ComboBoxItem> <ComboBoxItem>dsf gd</ComboBoxItem> <ComboBoxItem>hsf gd</ComboBoxItem> </ComboBox> 
Demand

is that the text in ComboBox can be selected, text search in the key file with the first entry, and comboBox must be editable. I set the properties

 IsReadOnly="True" IsEditable="True" 

but text search does not work. Help me solve this problem, please. Thanks in advance.

+4
source share
2 answers

Try IsTextSearchEnabled="True" TextSearch.TextPath="<PropertyName>" , where <PropertyName> is a property in the elements of your ItemsSource .

+11
source

I think you can solve your problem by removing the IsReadOnly property. You set to true, so the ComboBox does not accept any data. If you do not want the empty element to be the first ComboBox element, you can set SelectedIndex = "0".

+1
source

Source: https://habr.com/ru/post/1379290/


All Articles