Binding do just first time when element is obtained dynamically

Hi guys, i'm trying set bind each button width in a panel to a property called Mywidth in each Entity_Button in a colecction, but it takes value only first time, when i change the value's MyWidth does not update the value in Graphic_Button

foreach (Entity_Button Button_Entity_Current in DataContext.Collection_Entity_Buttons)
{
Button Graphic_Button = Panel_Buttons.FindByName(Button_Entity_Current.Name);
Graphic_Button.SetBinding(Button.WidthRequestProperty, new Binding("MyWidth", BindingMode.TwoWay, null, null, null, Button_Entity_Current));
}

Then i do:

Button_Entity.MyAncho = 120;

but Graphic_Button does not update him witdth.

But if i set the binding in a button that is not get in collection dynamically, then always change the value:

Graphic_Button.SetBinding(Button.WidthRequestProperty, new Binding("MyWidth", BindingMode.TwoWay, null, null, null, Entity_Button));

is ok,

I think the problem is when the button is dinamically obtain, then there's a bug that does not receipt the updates from binding,

please help

Answers

  • Humm, i did this way:

    foreach(Button Graphic_Button in Panel_Buttons.Children)
    {

    Button_Entity Button_Entity_Current = DataContext.Collection_Entity_Buttons.Where(x => x.Name == Graphic_Button.ClassId).First();

    Graphic_Button.SetBinding(Button.WidthRequestProperty, new Binding("MyWidth", BindingMode.TwoWay, null, null, null, Button_Entity_Current));

    }

    Thanks

Sign In or Register to comment.