private void PreloadDisabledImages() { foreach (object obj in Resources.Values) { ImageSource imageSource = (obj as ImageSource); if (null != imageSource) { AutoDisableImage.LoadImage(imageSource); } } }
protected static void OnAutoDisableImageIsEnabledPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs args) { AutoDisableImage image = GetImageWithSource(source); if (null != image) { bool isEnabled = Convert.ToBoolean(args.NewValue); image.Source = isEnabled ? image.OriginalImageSource : image.DisabledImageSource; image.Opacity = isEnabled ? 1.0 : 0.5; image.OpacityMask = isEnabled ? null : new ImageBrush(image.OriginalImageSource); } }
protected static AutoDisableImage GetImageWithSource(DependencyObject source) { AutoDisableImage image = source as AutoDisableImage; if (null == image) { return(null); } if (null == image.Source) { return(null); } return(image); }