WPF binding OneWayToSource sets source property to “” when the DataContext is changed

前端 未结 5 2034
再見小時候
再見小時候 2021-01-19 00:22

I have a OneWayToSource binding that is not behaving as I expected when I set the DataContext of the target control. The property of the source is being set to default inste

5条回答
  •  醉酒成梦
    2021-01-19 00:55

    Its a bug or perhabs not. Microsoft claims its by design. You first type x and then you kill DataContext by clicking on Button hence why the TextBox holds x and your viewModel.Text property gets newly initialized (its empty). When on datacontext changed getter will still be called. In the end you have no chance to fix this.

    You can however use two way and let it be.

提交回复
热议问题