E.g. if you have a TextBox named myTextBox having its Text property bound to some source then you can easily get it's UpdateSourceTrigger and Binding object via GetBindingExpression() call. var bndExp = BindingOperations.GetBindingExpression(myTextBox, TextBox.Textproperty); var myBinding = bndExp.ParentBinding; var updateSourceTrigger = myBinding.UpdateSourceTrigger;但是设置 UpdateSourceTrigger对于已经使用的绑定是很棘手的.例如.在上述情况下,您将无法将myBinding.UpdateSourceTrigger设置为其他设置.当绑定对象已经在使用中时,这是不允许的.But it is tricky to set UpdateSourceTrigger for an already used binding. E.g. in the above case you wont be able to set the myBinding.UpdateSourceTrigger to something else. This is not allowed when a binding object is already in use.您可能必须深克隆,并将绑定对象设置为新的UpdateSourceTrigger,然后将其分配回TextBox. Binding类不存在克隆.您可能必须为此编写自己的克隆代码.You may have to deep clone the binding object and set new UpdateSourceTrigger to it and assign it back to the TextBox. Cloning does not exist for Binding class. You may have to write your own cloning code for the same. var newBinding = Clone(myBinding); //// <--- You may have to code this function. newBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit; myTextBox.SetBinding(TextBox.TextProperty, newBinding);或者,您也可以尝试释放现有的绑定并进行更新并将其分配回... Alternately ou can also try to detatch the existing Binding and update it and assign it back... myTextBox.SetBinding(TextBox.TextProperty, null); myBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit; myTextBox.SetBinding(TextBox.TextProperty, myBinding);让我知道这些提示是否有帮助.Let me know if any of these tips helps. 这篇关于如何在代码隐藏中设置和获取文本框的updatesourcetrigger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 02:40