2 回答
TA贡献1836条经验 获得超5个赞
最后我明白了!
我必须将绑定源设置为原始文本框并将绑定设置为文本。这并不能 100% 回答问题,因为这可能不是关于在 WPF中保持两个文本框同步中的@AlvinfromDiaspar 评论的最有效解决方案, 但无论如何,它对我的目的来说足够好。
我改变了什么:
Binding binding = new Binding("Text");
binding.Source = (DependencyObject)this.FindName(BindingName);
绑定的整个片段:
String BindingName = inName.Substring(3);
BindingBase BB = BindingOperations.GetBindingBase(
(DependencyObject)this.FindName(BindingName),
TextBox.TextProperty);
var oldBind = BB as Binding;
if (BB != null)
{
//the magic goes here
Binding binding = new Binding("Text");
binding.Source = (DependencyObject)this.FindName(BindingName);
binding.Mode = BindingMode.OneWay;
binding.IsAsync = false;
binding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
binding.TargetNullValue = "null";
BindingOperations.SetBinding(tb, TextBox.TextProperty, binding);
}
- 2 回答
- 0 关注
- 163 浏览
添加回答
举报