Skip to content

Xamarin Forms custom login button bindable properties not set #2

@alperenbabagil

Description

@alperenbabagil

Hi,
First of all thanks for this great tutorial. I implemented the facebook login button but after clicking and completing login OnSuccess,OnFail and OnError callbacks not triggered on viewModel. After some digging code realized that custom view bindable properties not set. So triggering callbacks in native side stopped because custom view's properties is null. So I changed little bit and putting one example for a Binding Property of custom login button.
Happy coding!

FacebookLoginButton.cs:

        // this is the Bindable property. Added property changed property to set manually
        public static readonly BindableProperty OnSuccessProperty =
            BindableProperty.Create(nameof(OnSuccess), typeof(Command<string>), typeof(FacebookLoginButton), propertyChanged: OnSuccessPropertyChanged);

        static void OnSuccessPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            ((FacebookLoginButton)bindable).OnSuccessPropertyChanged((Command<string>)oldValue, (Command<string>)newValue);
        }

        void OnSuccessPropertyChanged(Command<string> oldValue, Command<string> newValue)
        {
            OnSuccess = newValue; //setting command value
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions