Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top