2

我公开了一个集合并将其绑定到自动完成框的项目源,它可以工作,但选择或更改自动完成框上的文本不会像文本框或标签那样更新模型!

视图模型:

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"/>
4

1 回答 1

8

要从用户界面更改回视图模型,您将始终需要绑定属性 TwoWay(除了一些属性,如 TextBox.TextProperty默认为 TwoWay ):

<controls:AutoCompleteBox 
    ItemsSource="{Binding SymptomsDb}" 
    SelectedItem="{Binding Symptom, Mode=TwoWay}" 
    Text="{Binding Symptom}" 
    IsTextCompletionEnabled="True" 
    FilterMode="Contains"/>
于 2013-03-05T15:50:06.583 回答