WPF two-way binding not working

后端 未结 4 1017
迷失自我
迷失自我 2020-12-16 15:30

I have a data context (UserPreferences) assigned to my main window, and a textbox that binds two-way to a property within one of the data context\'s properties

4条回答
  •  眼角桃花
    2020-12-16 15:43

    By default, the Text property of TextBox is updated only when the focus on it is lost. Did you verify it with your DataContext?

    If you want to override this behaviour, you have to include the property UpdateSourceTrigger in this way:

    Text="{Binding Path=SelectedCollectionDevice.BaudRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}
    

    Setting UpdateSourceTrigger's value to PropertyChanged, the change is reflected in the TextBox when you change the value of your bound property, as soon as the text changes.

    A useful tutorial about the usage of UpdateSourceTrigger property is here.

提交回复
热议问题