Пример #1
0
            private async void FinishLoad(Task <IEnumerable <Tuple <string, string> > > imagesTask)
            {
                _finishedImages = new List <Tuple <string, string> >(imagesTask.Result);
                bool hasGifs = false;

                for (int i = 0; i < _finishedImages.Count; i++)
                {
                    var renderer = GifRenderer.CreateGifRenderer(await DownloadImageFromWebsiteAsync(_finishedImages[i].Item2));
                    if (renderer != null)
                    {
                        _imageSources.Add(i, renderer);
                        hasGifs = true;
                    }
                }


                if (hasGifs)
                {
                    Messenger.Default.Register <PageChangeMessage>(this, OnPageChange);
                }


                IsLoading = false;
                RaisePropertyChanged("ImageSource");
                RaisePropertyChanged("IsLoading");
                RaisePropertyChanged("IsAlbum");
                RaisePropertyChanged("AlbumSize");
                CurrentPosition = 0;
            }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override async void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            var pictureData = navigationParameter as IEnumerable <Tuple <string, string> >;

            if (pictureData == null && pageState != null && pageState.ContainsKey("NavagationData"))
            {
                _navData = pictureData = pageState["NavagationData"] as IEnumerable <Tuple <string, string> >;
            }

            if (pictureData != null)
            {
                _navData = pictureData;
                var pictureTasks = pictureData.Select(async(tpl) =>
                {
                    var renderer = GifRenderer.CreateGifRenderer(await DownloadImageFromWebsiteAsync(tpl.Item2));
                    if (renderer != null)
                    {
                        renderer.Visible = true;
                        return(new LinkedPictureViewModel.LinkedPicture {
                            Title = tpl.Item1, ImageSource = renderer
                        });
                    }
                    else
                    {
                        return new LinkedPictureViewModel.LinkedPicture {
                            Title = tpl.Item1, ImageSource = tpl.Item2
                        }
                    };
                })
                                   .ToArray();

                _pictureViewModel = new LinkedPictureViewModel
                {
                    Pictures = await Task.WhenAll(pictureTasks)
                };
            }

            DataContext = _pictureViewModel;
        }