Welcome to the Xamarin.Forms feedback portal. We’re happy you’re here! If you have feedback on how to improve the Xamarin.Forms, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

0
Votes

It is usually desirable that when a BusyIndicator is Running, that other controls are disabled and faded.

Instead of Binding Opacity and IsEnabled on the other controls, I have added an attached property to my version of the BusyIndicator which allows other controls to register with it so when the BusyIndicator enters the Running state, the other controls are set to Disabled and the Opacity is faded.

The BusyIndicator defines a List<View> Dependents. which is a List of all controls that have "attached" to this control.

private List<View> Dependents;


The attached property is defined as 

/// Attached Property starts here

  public static readonly BindableProperty IndicatorProperty = BindableProperty.CreateAttached("Indicator",
            typeof(MyBusyIndicator), typeof(MyBusyIndicator), null, propertyChanged: IndicatorPropertyChanged);

        private static void IndicatorPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
        {
            if (newvalue is MyBusyIndicator indicator)
            {
                if (bindable is View view)
                {
                    if (!indicator.Dependents.Contains(view))
                        indicator.Dependents.Add(view);
                }
            }
        }

        public static View GetIndicator(BindableObject view)
        {
            return (MyBusyIndicator) view.GetValue(IndicatorProperty);
        }

        public static void SetIndicator(BindableObject view, MyBusyIndicator value)
        {
            view.SetValue(IndicatorProperty, value);
        }


Then in the BusyIndicator when the IsRunning Property changes I do the following..


 private static void IsRunningPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
        {
            if (bindable is MyBusyIndicator ctl)
            {
                var isRunning = (bool) newvalue;
                foreach (var dependent in ctl.Dependents)
                {
                    dependent.IsEnabled = !isRunning;
                    dependent.Opacity = isRunning ? 0.6 : 1.0;
                }
            }
        }


That is all!!!


The feature is used by any view on a Page or View as follows. Any View that sets the attached property adds itself to that MyBusyIndicator's Dependents List. So the View's IsEnabled and Opacity will change based on that BusyIndicator's IsRunning value.

<Grid MyBusyIndicator.Indicator="{x:Reference BusyIndicator}">
</Grid>
<SfListView
MyBusyIndicator.Indicator="{x:Reference BusyIndicator}"
>
</SfListView>

<MyBusyIndicator x:Name="BusyIndicator" IsRunning={Binding IsBusy}" />