How to mimic a “type in” behavior (text search) of not opened focused combo box in WPF?

StackOverflow https://stackoverflow.com/questions/10566836

Question

Standard WPF combo box has the type in functionality. That is: when combo box has a focus and user types some letters, selected item in combo box changes (in relation to typed letters).

Important

I do not mean combo box with IsEditable set to True, neither I mean opened list of combo box. I mean pure simple combo box with several text items:

enter image description here

The question

How can I mimic this behavior in my custom build combo box? (it is built from scratch, and mimics everything, except mentioned functionality).

My combo box was built using classic schema: a toogle button, a popup, and a list box inside popup (assuming I do not include all the additional functionality in described schema). List box supports "type in" functionality perfectly. So my idea was to bring all the keystrokes from toggle button to list box:

Private Sub MyToggleButton_PreviewKeyDown(sender As Object, e As System.Windows.Input.KeyEventArgs) Handles MyToggleButton.PreviewKeyDown
    MyListBox_PreviewKeyDown(Me, e)
End Sub

Private Sub MyListBox_PreviewKeyDown(sender As Object, e As System.Windows.Input.KeyEventArgs) Handles MyListBox.PreviewKeyDown
    MyBase.OnPreviewKeyDown(e)
End Sub

But for some reason it does not work.

Était-ce utile?

La solution

Check out this article.

http://www.codeproject.com/Articles/66890/A-Keyboard-Selection-Enabled-ComboBox-in-Silverlig

Though the article is intended for silvelight it show should so you the steps needed.

Unless you post the code on how you have implemented the combobox no one can give a complete solution

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top