0

I'm creating some custom View element:

public class ExtendableButtonList : StackLayout
{
    public static readonly BindableProperty NewSlotNameProperty = BindableProperty.Create(
      propertyName: "NewSlotName",
      returnType: typeof(string),
      declaringType: typeof(ExtendableButtonList),
      defaultValue: default(string));

    public string NewSlotName
    {
        get { return (string)GetValue(NewSlotNameProperty); }
        set { SetValue(NewSlotNameProperty, value); }
    }

    public delegate void OnLoadHandler(ExtendableButtonList ebl);
    public event OnLoadHandler OnLoadEvent;

    public ExtendableButtonList (){
       //not all properies are loaded at this point
    }
    [...]
}

I need to do some actions on properties that are passed through XAML to this object. Unfortunately, when constructor of ExtendableButtonList class is being called, not all BindableProperties are loaded at this time. They appear later on.

How would I know when all properties are loaded in this object? When to call OnLoadEvent to let my app know that this object is ready for further usage?

Piotrek
  • 10,919
  • 18
  • 73
  • 136
  • 1
    did you tried to override the OnBindingContextChanged? Guess its a good place to check that. – jzeferino Jun 29 '16 at 15:31
  • 1
    @jzeferino is correct. I've answered a similar/duplicate question here: http://stackoverflow.com/questions/37867863/how-to-get-contentpages-bindingcontext-from-contentview – Rodrigo Elias Jun 29 '16 at 16:54
  • I added my answer in the post. since this is not a duplicate of that question. thank you. – jzeferino Jun 29 '16 at 16:56

1 Answers1

1

In this particular case, you should override the OnBindingContextChanged to do that validations.

You can see here a good explanation about the OnBindingContextChanged

Community
  • 1
  • 1
jzeferino
  • 7,700
  • 1
  • 39
  • 59