Пример #1
0
        private void CoverImage_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            var book = DataContext as Book;

            if (book == null)
            {
                return;
            }
            var filePath = AppDataPath.GetBookCoverPath(book.BookId);

            if (filePath == null)
            {
                if (!string.IsNullOrEmpty(book.Cover))
                {
                    DownloadCoverHelper.SaveHttpImage(AppDataPath.GetBookCoverFolderPath(), book.BookId + ".jpg",
                                                      book.Cover,
                                                      SetCoverImage);
                }
                else
                {
                    this.ImageCover.Source = null;
                }
            }
            else
            {
                this.ImageCover.Source = new BitmapImage(new Uri(filePath, UriKind.Absolute));
            }
        }
Пример #2
0
        private static void OnBookValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as CoverImage;
            var book    = control?.CurrentBook;

            //  var book = DataContext as Book;
            if (book == null)
            {
                if (control != null)
                {
                    control.ImageCover.Source = null;
                }
                return;
            }
            var filePath = AppDataPath.GetBookCoverPath(book.BookId);

            if (filePath == null)
            {
                if (!string.IsNullOrEmpty(book.Cover))
                {
                    DownloadCoverHelper.SaveHttpImage(AppDataPath.GetBookCoverFolderPath(), book.BookId + ".jpg",
                                                      book.Cover,
                                                      control.SetCoverImage);
                }
                else
                {
                    control.ImageCover.Source = null;
                }
            }
            else
            {
                control.ImageCover.Source = new BitmapImage(new Uri(filePath, UriKind.Absolute));
            }
        }
Пример #3
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var defaultValue = new BitmapImage(new Uri("ms-appx:Assets/Icon/cover.png", UriKind.Absolute));
            var book         = value as Book;

            if (string.IsNullOrEmpty(book?.Cover))
            {
                return(defaultValue);
            }
            var filePath = AppDataPath.GetBookCoverPath(book.BookId);

            if (filePath == null)
            {
                DownloadCoverHelper.SaveHttpImage(AppDataPath.GetBookCoverFolderPath(), book.BookId + ".jpg", book.Cover);
            }
            return(filePath == null ? new BitmapImage(new Uri(book.Cover, UriKind.RelativeOrAbsolute)) : new BitmapImage(new Uri(filePath, UriKind.Absolute)));
        }