11 comments on “Image UserControl with FadeIn & FadeOut Animation for WinRT

  1. Pingback: Image UserControl with FadeIn & FadeOut Animation for WinRT

  2. Pingback: Image UserControl with FadeIn & FadeOut Animation for WinRT | Answer My Query

  3. Pingback: Windows Store Developer Links – 2013-05-29 | Dan Rigby

  4. Excellent sample! I made something similar in my project when I wanted to animate image changes.
    There is just one problem in your sample that I should warn you about, considering that you are using the same storyboard every time and that LoadImage method could be called more than once. Using lambda to add a handler for storyboard completed event will create and add a new one every time LoadImage is executed. This is OK if you are using temporary storyboards to play animation only once before disposing of it but it is not the case here.
    A good way around that would be to define event handler first so you can reference to itself in order to unsubscribe from completed event when it completes.

    The body of LoadImage method should look like this:

    EventHandler handler = null;
    handler = delegate
    {
        ImageFadeOut.Completed -= handler;
        Image.Source = source;
        ImageFadeIn.Begin();
    };
    ImageFadeOut.Completed += handler;
    ImageFadeOut.Begin();
    

    Liked by 1 person

    • I solved this by just declaring the handler once in the constructor isnce there’s really no need to pass source to the handler as it is held by the Staging element.

      public ImagePreview()
      {
      this.InitializeComponent();
      ImageFadeOut.Completed += (o, e) =>
      {
      Image.Source = this.Staging.Source;
      ImageFadeIn.Begin();
      };
      }

      private static void SourceChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
      {
      var control = (ImagePreview)dependencyObject;
      var image = dependencyPropertyChangedEventArgs.NewValue as BitmapImage;

      if (image != null)
      {
      // If the image is not a local resource or it was not cached
      if (image.UriSource.Scheme != “ms-appx” && image.UriSource.Scheme != “ms-resource” && (image.PixelHeight * image.PixelWidth == 0))
      {
      image.ImageOpened += (sender, args) => control.ImageFadeOut.Begin();
      control.Staging.Source = image;
      }
      else
      {
      control.ImageFadeOut.Begin();
      }
      }
      }

      Like

  5. Selam Can,
    3 resim var. İstiyorum ki repeat bir şekilde image show olsun. Windows Phone 8.1 için en basitinden fade in fade out olacak bir şekilde. Animasyon yapmak için uğraşıyorum, araştırıyorum ancak başarılı olamadım. En sonunda Google ile senin siteyi buldum. Cevap yazarsan mutlu olurum 🙂

    Like

    • selam Burhan,
      turkiye’den comment falan gelince cok mutlu oluyorum 🙂
      iki uc resmi rotate etcek bi control icin, fikrin ayni olmasi lazim… sadece placeholder elementinin yerine diger resimleri load edebilmeck icin Image control ekleyip timerla degisimi halledebilecegini dusunuyorum… zamanim oldugun da bi bakayim ornegi genisletebilirim belkide… bol sanslar…

      Like

  6. İnceledim kodlarınızı, İngilizce bilmiyorum ancak isminizi sonradan fark ettim ve gördüm ki , yazınızı Türkçe yazmamışsınız. İngilizce yazmanıza söylenecek bir söz yok kendi adınıza ve bir çok insana çok yararı da olabilir tabi ancak neden Türkçe değil?! Bütün bunları kendime sordum ama bir de size sormak istedim.

    Like

Leave a comment