/// <summary> /// Invoked when bitmap's Source property is changed. /// </summary> /// <param name="dependencyObject">Dependency object - bitmap.</param> /// <param name="eventArgs">Event data.</param> private static void _OnSourceChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs) { // Get bitmap. BitmapUIElement bitmap = (BitmapUIElement)dependencyObject; // Get old bitmap source value. BitmapSource oldBitmapSourceValue = (BitmapSource)eventArgs.OldValue; // Get new bitmap source value. BitmapSource newBitmapSourceValue = (BitmapSource)eventArgs.NewValue; // Unsubscribe from events for old bitmap source value. if (oldBitmapSourceValue != null && !oldBitmapSourceValue.IsFrozen) { oldBitmapSourceValue.DownloadCompleted -= bitmap._OnBitmapSourceDownloadCompleted; oldBitmapSourceValue.DownloadFailed -= bitmap._OnBitmapSourceDownloadFailed; } // Subscribe to events for the new bitmap source value. if (newBitmapSourceValue != null && !newBitmapSourceValue.IsFrozen) { newBitmapSourceValue.DownloadCompleted += bitmap._OnBitmapSourceDownloadCompleted; newBitmapSourceValue.DownloadFailed += bitmap._OnBitmapSourceDownloadFailed; } }
/// <summary> /// Initializes a new instance of <c>SmartBitmap</c>. /// </summary> public SmartBitmap() { _bitmapUIElement = new BitmapUIElement(); AddVisualChild(_bitmapUIElement); }