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?

有帮助吗?

解决方案

If DatabaseField is read-only you should use OneWay Binding.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top