1. How to properly bind data from a database to a ComboBox so that it always contains relevant data for the sample, using MVVM ?
  2. How to make the opportunity not just to select an element from the ComboBox , but also to give the user the opportunity to enter the name of the element with the possibility of auto-completion.

Let the user need to choose the name of the city. He enters "М" and the prompt "Мадрид" immediately appears, but if he continues to enter a name that is not in the database, say "Мюнхен" , then a field should appear with the ability to choose from which country this city is.

1 answer 1

Quite voluminous questions.

  1. There is no one right way. I use the Entyty Framework and in the ViewModel I keep the collection with the necessary elements, updating it periodically when the context and other events change.
 public ObservableCollection<AccountViewModel> AccountList => new ObservableCollection<AccountViewModel>(_dataService.GetAccounts().Select(a => new AccountViewModel(a))); 

Here you can add Where to filter or anything.

  1. In general, the whole engineering task, to fully implement is not easy, you need your user control. ComboBox does not provide the necessary functionality, you need to look for third-party controls, or write your own from scratch or based on a ComboBox .