2
我公開了一個集合並將其綁定到了自動完成框的itemsource,但是選擇或更改autocompletebox上的文本並不像文本框或標籤那樣更新模型!如何使用mvvm中的模型綁定自動完成框?
視圖模型:
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);
}
觀點:
<controls:AutoCompleteBox
ItemsSource="{Binding SymptomsDb}"
SelectedItem="{Binding Symptom}"
Text="{Binding Symptom}"
IsTextCompletionEnabled="True"
FilterMode="Contains"/>
謝謝。爲了理解爲什麼控件不會將Text屬性正確綁定到IDataErrorInfo類,我迷失了幾個小時。 – andySF 2014-02-28 14:26:18