예제 #1
0
        private static void UriSourcePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var img = o as LazyImage;
            var uri = e.NewValue as Uri;

            if (img == null)
            {
                return;
            }
            if (uri != null)
            {
                try
                {
                    if (uri.Scheme == "pack")
                    {
                        var bi = new BitmapImage();
                        bi.BeginInit();
                        bi.UriSource   = uri;
                        bi.CacheOption = BitmapCacheOption.OnLoad;
                        bi.EndInit();
                        bi.Freeze();
                        SetImage(img, bi, uri);
                    }
                    else
                    {
                        bool hitCache = false;
                        try
                        {
                            var cache = ImageCacheStorage.GetImageCache(uri);
                            if (cache != null)
                            {
                                SetImage(img, cache, uri);
                                hitCache = true;
                            }
                            else
                            {
                                if (img.DefaultImage == null || img.DefaultImage == DependencyProperty.UnsetValue)
                                {
                                    // img.Source = null causes binding error.
                                    img.SetValue(Image.SourceProperty, DependencyProperty.UnsetValue);
                                }
                                else
                                {
                                    img.Source = img.DefaultImage.CloneFreezeNew();
                                }
                            }
                        }
                        catch
                        {
                            hitCache = false;
                        }
                        if (!hitCache)
                        {
                            taskrun.Push(() =>
                            {
                                try
                                {
                                    var bi = ImageCacheStorage.DownloadImage(uri);
                                    Application.Current.Dispatcher.BeginInvoke(() => SetImage(img, bi, uri),
                                                                               DispatcherPriority.ContextIdle);
                                }
                                catch { }
                            });
                        }
                    }
                }
                catch { }
            }
        }
예제 #2
0
 private void ClearImageCaches()
 {
     ImageCacheStorage.ClearAllCache();
 }