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!>
Thanks for joining our community and helping improve Syncfusion products!
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;
}
}
}