Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms Bindable Properties

It may sound like a dumb question but why are bindable properties static?

public static readonly BindableProperty MapSpanProperty = BindableProperty.Create(
    propertyName: "MapSpan",
    returnType: typeof(MapSpan),
    declaringType: typeof(BindableMap),
    defaultValue: null,
    defaultBindingMode: BindingMode.TwoWay,
    propertyChanged: MapSpanPropertyChanged);

public MapSpan MapSpan
{
    get
    {
        return (MapSpan)GetValue(MapSpanProperty);
    }
    set
    {
        SetValue(MapSpanProperty, value);
    }
}

I have this code and it works just fine if I make the bindable property static, otherwise, it doesn't work. If I make this bindable property static it means, let's say if I have 2 maps opened at the same time, that this value will be the same on both if I set it on one of them?


1 Answers

As far as I understand, it's static just for get describing data before moment of creation. But it's not being used as static. BindableObject base class define INSTANСE of Dictionary<BindablePropery, BindablePropertyContext>. BindablePropertyContext contains our value. It means that each our class has static BindablePropery, but every of them get it's own context from it's own dictionary.

like image 190
ereteysaber Avatar answered Jul 28 '26 15:07

ereteysaber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!