Why I get the message Two-way binding requires Path or XPath.?
-
28-06-2021 - |
Pregunta
I am creating a TextBox
and a TextBlock
at runtime and bind that to the database fields at runtime. The code is below:
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.
Where am I going wrong?
Solución
If DatabaseField is read-only you should use OneWay Binding.
Otros consejos
If the Text
property of the bound object contains symbols specific to XPath
syntax, dynamic binding will try to interpret them, thus failing you the whole process by creating wrong binding
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow