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
TextBox has a Binding in it's TextProperty and when you set TextBox's DataContext, TextBox will update it's source (viewmodel.Text) , no matter which type of the UpdateSourceTrigger.
It's said that the first output in viewmodel
"ViewModel.Text (old value=
"
is not triggered by UpdateSourceTrigger=PropertyChanged
.
It's just a process of init:
private string _Text;
public string Text
{
get { return _Text; }
set
{
Debug.Print(
"ViewModel.Text (old value=" + (_Text ?? "") +
", new value=" + (value ?? "") + ")");
_Text = value;
}
}
Because it's not triggered by UpdateSourceTrigger=PropertyChanged
, the viewmodel will not know the value of TextBox.Text.
When you type "Y",the trigger of PropertyChanged will working,so the viewmodel read text of TextBox.