Exemple #1
0
        private void MainPage_OnFrameChanged(object sender)
        {
            GifImageSource gifImage = (GifImageSource)sender;

            _progressBar.Value   = gifImage.CurrentFrame;
            _progressBar.Maximum = gifImage.FrameCount;
        }
        private void AppBarButtonPause_Click(object sender, RoutedEventArgs e)
        {
            GifImageSource source = AnimationBehavior.GetGifImageSource(_gifImage);

            if (source != null)
            {
                source.Pause();
            }
        }
Exemple #3
0
        private void Play_Click(object sender, RoutedEventArgs e)
        {
            GifImageSource source = AnimationBehavior.GetGifImageSource(_gifImage);

            if (source != null)
            {
                source.Start();
            }
        }
Exemple #4
0
        private void Stop_Click(object sender, RoutedEventArgs e)
        {
            GifImageSource source = AnimationBehavior.GetGifImageSource(_gifImage);

            if (source != null)
            {
                source.Stop();
            }
            _progressBar.Value = 0;
        }
Exemple #5
0
 private void Sc_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
 {
     if (IsPausedWhileScrolling)
     {
         if (e.IsIntermediate)
         {
             GifImageSource.PauseAllGifs();
         }
         else
         {
             //scroll is stopping
             GifImageSource.ResumeAllGifs();
         }
     }
 }
Exemple #6
0
        public ListViewTest()
        {
            this.DataContext = this;

            this.InitializeComponent();
#if WINDOWS_APP
            this.navBackButton.Style      = (Style)Resources["NavigationBackButtonNormalStyle"];
            this.navBackButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
            _scrollResumeTimer.Interval   = TimeSpan.FromMilliseconds(500);
            _scrollResumeTimer.Tick      += (s, args) =>
            {
                _scrollResumeTimer.Stop();
                GifImageSource.ResumeAllGifs();
            };
#elif WINDOWS_PHONE_APP
            HardwareButtons.BackPressed += HardwareButtons_BackPressed;
#endif
        }
Exemple #7
0
        private void Sc_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            if (IsPausedWhileScrolling)
            {
#if WINDOWS_APP
                _scrollResumeTimer.Stop();
                _scrollResumeTimer.Start();
                GifImageSource.PauseAllGifs();
#else
                if (e.IsIntermediate)
                {
                    GifImageSource.PauseAllGifs();
                }
                else
                {
                    //scroll is stopping
                    GifImageSource.ResumeAllGifs();
                }
#endif
            }
        }
Exemple #8
0
        private void ResetImage()
        {
            if (!HasImage)
            {
                return;
            }

            _surface.Background = null;

            if (_brush != null)
            {
                _brush.ImageSource = null;
                _brush             = null;
            }

            if (_source != null)
            {
                _source.ClearResources();
                _source = null;
            }

            HasImage = false;
        }
Exemple #9
0
        private async void ShowImage()
        {
            if (!CanLoad || !HasAppliedTemplate || !IsLoaded || HasImage)
            {
                return;
            }

            ResetImage();
            if (UriSource == null)
            {
                return;
            }

            SetProgress(0);
            VisualStateManager.GoToState(this, "Unloaded", true);

            // For thread safety, save current value of UriSource
            var uriSource = UriSource;

            HasImage = true;
            using (var stream = await GetImageStreamAsync(uriSource)) // This is not thread-safe!
            {
                // Technically, at each await exists the possibility that UriSource can be changed.
                // We need to ensure that this hasn't happened, otherwise we run the risk of leaking resources
                // or doing other bad things.
                if (uriSource != UriSource)
                {
                    return;
                }

                if (stream == null)
                {
                    VisualStateManager.GoToState(this, "Failed", true);
                    return;
                }

                try
                {
                    var decoder = await BitmapDecoder.CreateAsync(stream);

                    var source = new GifImageSource((int)decoder.PixelWidth, (int)decoder.PixelHeight)
                    {
                        EnablePrerender = true
                    };
                    await source.SetSourceAsync(stream);

                    // It's possible that the URI changed, or the control has been unloaded, etc. If so,
                    // clear resources and quit.
                    if (uriSource != UriSource || !IsLoaded || !CanLoad)
                    {
                        // Clean up GifImageSource and return
                        source.ClearResources();
                        return;
                    }

                    // Must wait for async operations to complete before setting _source
                    _source = source;
                }
                catch (Exception)
                {
                    VisualStateManager.GoToState(this, "Failed", true);
                    return;
                }
            }

            _brush = new ImageBrush {
                ImageSource = _source, Stretch = Stretch.None
            };
            _surface.Background = _brush;

            _surface.Height = _source.Height;
            _surface.Width  = _source.Width;

            // Render one frame so that we show something even if the gif is paused
            _source.RenderFrame();

            VisualStateManager.GoToState(this, "Loaded", true);

            CheckTimer();

            _fireImageOpened = true;
        }