ActivityIndicator switch binding

Jan-DavidStrkJan-DavidStrk USMember ✭✭
edited September 2016 in Xamarin.Forms

Hey,

probably just a minor issue. I add an Activity Indicator to my UI (in C#, not xaml) but whenever I switch from the Binding "IsBusy" to something different "IsBusyNew", it just doesn't work.
indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy"); //Works
indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusyNew"); //Doesn't work
IsBusyNew:
public bool IsBusyNew { get; set; }

What am I doing wrong?

Best Answer

  • ChaseFlorellChaseFlorell CA mod
    edited September 2016 Accepted Answer

    Your property must indicate to the view when the value changes. A simple auto-property won't cut it.

    If you're using a ViewModel, then it should implement INotifyPropertyChanged and your setter should notify. If you're not using a ViewModel, and simply binding to a property on your page, then either just use IsBusy (which you're saying works), or wire up your property as bindable.

            public static readonly BindableProperty NewIsBusyProperty = BindableProperty.Create(nameof(NewIsBusy),
                typeof (bool),
                typeof (MyPage),
                null);
    
            /// <summary>
            ///    NewIsBusy summary. This is a bindable property.
            /// </summary>
            public bool NewIsBusy
            {
                get { return (bool) GetValue(NewIsBusyProperty); }
                set { SetValue(NewIsBusyProperty, value); }
            }
    

Answers

  • JulienRosenJulienRosen CAMember ✭✭✭✭

    your bool property needs to implement INPC

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited September 2016 Accepted Answer

    Your property must indicate to the view when the value changes. A simple auto-property won't cut it.

    If you're using a ViewModel, then it should implement INotifyPropertyChanged and your setter should notify. If you're not using a ViewModel, and simply binding to a property on your page, then either just use IsBusy (which you're saying works), or wire up your property as bindable.

            public static readonly BindableProperty NewIsBusyProperty = BindableProperty.Create(nameof(NewIsBusy),
                typeof (bool),
                typeof (MyPage),
                null);
    
            /// <summary>
            ///    NewIsBusy summary. This is a bindable property.
            /// </summary>
            public bool NewIsBusy
            {
                get { return (bool) GetValue(NewIsBusyProperty); }
                set { SetValue(NewIsBusyProperty, value); }
            }
    
Sign In or Register to comment.