//See: http://blog.ningzhang.org/2008/11/dependencyproperty-validation-coercion.html /// <summary> /// This ensures the Busy will not be false, untill the last Busy call is dealt with /// It will keep the value true untill the counter is 0 /// </summary> /// <param name="d"></param> /// <param name="value"></param> /// <returns></returns> private static object CoerceBusyProperty(DependencyObject d, object value) { BusyIndicatorControl busyControl = (BusyIndicatorControl)d; bool val = (bool)value; if (val == false && busyControl.BusyMode == BusyMode.BusyIfTrue) { // if the user set it to false, then HideBusy will decriment the counter, and determine if this is the last one // if it is the last one we will get back a false, if it isn't we will leave the busy value at true return(busyControl.HideBusy()); } else if (val == true && busyControl.BusyMode == BusyMode.BusyIfTrue) { busyControl.ShowBusy(); return(true); } else if (val == false && busyControl.BusyMode == BusyMode.BusyIfFalse) { busyControl.ShowBusy(); return(true); } else if (val == true && busyControl.BusyMode == BusyMode.BusyIfFalse) { return(busyControl.HideBusy()); } throw new NotImplementedException("Should never reach this point. All conditions should be covered"); }
private static void BusyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { BusyIndicatorControl busyControl = (BusyIndicatorControl)d; }