Вопрос

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