-
I'm new to Avalonia and trying to figure things out. Currently I am trying to set up an auto-complete box control where the item selection is bound to an observable collection of objects. Sounds like it should be easy, right? turns out it doesn't seem to be. I have a semi working method using a combo box, but would prefer the user be able to type in the selection vs having to switch to the mouse, then back to typing for form fill in. xaml for the working combobox:
In a perfect world I would expect to be able to just switch around some names and the AutoCompleteBox would be an essentially drop-in replacement. Apparently, I am wrong and the autocomplete box seems to have significantly different behavior to the Combo box. My current kinda not working autocomplete xaml:
This code only kind of works. I get a proper dropdown showing the correct information. That is what works. I don't know if I am just doing something horribly wrong, or if the autocomplete box is just not a complete feature, and I need to look into other options. Any help would be appreciated. edited to try and clean up code presentation |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Would override ToString in your ItemViewModel be a solution for you? |
Beta Was this translation helpful? Give feedback.
-
The autocompletebox looks like it searches on the result of calling ToString on the objects in the ItemSource. Looking at the example in the ControlCatalog sample it look like you can either use the property ValueMemberBinding to bind to a specific member of the object or create a value converter which allows you to return any string you want from the binding. |
Beta Was this translation helpful? Give feedback.
The autocompletebox looks like it searches on the result of calling ToString on the objects in the ItemSource. Looking at the example in the ControlCatalog sample it look like you can either use the property ValueMemberBinding to bind to a specific member of the object or create a value converter which allows you to return any string you want from the binding.