wpf 为什么我收到消息双向绑定需要 Path 或 XPath。?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12157360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why I get the message Two-way binding requires Path or XPath.?
提问by sony
I am creating a TextBoxand a TextBlockat runtime and bind that to the database fields at runtime. The code is below:
我在运行时创建 aTextBox和 aTextBlock并在运行时将其绑定到数据库字段。代码如下:
LstConfigFields = dbContext.ConfigFields.Where(c => c.ConfigId == this.Uid).ToList();
foreach (ConfigField rec in LstConfigFields)
{
TextBlock TBlock = new TextBlock();
TBlock.Text = rec.TextBlockText;
TextBox TBox = new TextBox();
TBox.SetBinding(TextBox.TextProperty,new Binding(rec.DatabaseField));
if ((bool)rec.IsVisible)
{
stackPanel1.Children.Add(TBlock);
stackPanel1.Children.Add(TBox);
}
}
But I am getting this message :
但我收到这条消息:
Two-way binding requires Path or XPath.
双向绑定需要 Path 或 XPath。
Where am I going wrong?
我哪里错了?
回答by Rover
If DatabaseField is read-only you should use OneWay Binding.
如果 DatabaseField 是只读的,您应该使用OneWay Binding。
回答by George
If the Textproperty of the bound object contains symbols specific to XPathsyntax, dynamic binding will try to interpret them, thus failing you the whole process by creating wrong binding
如果Text绑定对象的属性包含特定于XPath语法的符号,动态绑定将尝试解释它们,从而通过创建错误的绑定使您整个过程失败

