how to bind an autocompletebox with a model in mvvm?

mvvm, wpftoolkit

Solution

To get a change from the user interface back to the viewmodel, you will always need to bind the property TwoWay (except some properties like TextBox.TextProperty that are TwoWay by default):

<controls:AutoCompleteBox 
    ItemsSource="{Binding SymptomsDb}" 
    SelectedItem="{Binding Symptom, Mode=TwoWay}" 
    Text="{Binding Symptom}" 
    IsTextCompletionEnabled="True" 
    FilterMode="Contains"/>

Problem

i exposed a collection and binded it to itemsource of autocompletebox which works but selecting or changing the text on the autocompletebox doesn't update the model like a textbox or a label! viewmodel: ``` public ObservableCollection<String> SymptomsDb { get; private set; } private String symptom; public String Symptom { get { return symptom; } set { symptom = value; RaisePropertyChanged(() => this.Symptom); } } public AnalysisViewModel() { List<String> s = new List<String>(); s.Add("test"); SymptomsDb = new ObservableCollection<String>(s); } ``` view: ``` <controls:AutoCompleteBox ItemsSource="{Binding SymptomsDb}" SelectedItem="{Binding Symptom}" Text="{Binding Symptom}" IsTextCompletionEnabled="True" FilterMode="Contains"/> ```

Original source