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

前端 未结 5 1945
再見小時候
再見小時候 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:57

    Here you will have to UpdateSource like below:

     private void Button1_Click(object sender, RoutedEventArgs e)
       {
    
          Debug.Print("'Set DataContext' button clicked");
          tb.DataContext = _vm;
          var bindingExp = tb.GetBindingExpression(TextBox.TextProperty);
          bingExp.UpdateSource();
       }
    

提交回复
热议问题