/// <summary> /// Callback when the IsGreyable property is set or changed. /// </summary> private static void OnChangedIsGreyable(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { Image image = dependencyObject as Image; if (null != image) { if ((bool)e.NewValue) { // turn greyability effect on if it is not turned on yet if (image.ReadLocalValue(GreyabilityEffectProperty) == DependencyProperty.UnsetValue) { ImageGreyer greyability = new ImageGreyer(image); image.SetValue(GreyabilityEffectProperty, greyability); } } else { // remove greyability effect if (image.ReadLocalValue(GreyabilityEffectProperty) != DependencyProperty.UnsetValue) { ImageGreyer greyability = (ImageGreyer)image.ReadLocalValue(GreyabilityEffectProperty); greyability.Detach(); image.SetValue(GreyabilityEffectProperty, DependencyProperty.UnsetValue); } } } }