Example #1
0
        public void SetImageSource(ImageSource image, bool animateOpacity)
        {
            if (image != null && Brush.ImageSource == null)
            {
                if (animateOpacity)
                {
                    var bitmap = image as BitmapSource;

                    if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
                    {
                        bitmap.DownloadCompleted += BitmapDownloadCompleted;
                        bitmap.DownloadFailed    += BitmapDownloadFailed;
                    }
                    else
                    {
                        Brush.BeginAnimation(ImageBrush.OpacityProperty, new DoubleAnimation(1d, AnimationDuration));
                    }
                }
                else
                {
                    Brush.Opacity = 1d;
                }
            }

            Brush.ImageSource = image;
            HasImageSource    = true;
        }
Example #2
0
        public static void AnimateImageSourceChange(this Brush background, ImageBrush newImage,
                                                    Action <ImageBrush> onChangeImage, AnimateImageChangeParams animateImageChangeParams = null)
        {
            var animationParameters = animateImageChangeParams ?? new AnimateImageChangeParams();

            if (background != null)
            {
                var fadeOutAnimation = new DoubleAnimation(0d, animationParameters.FadeTime)
                {
                    AutoReverse = false
                };
                var fadeInAnimation =
                    new DoubleAnimation(0d, animationParameters.TargetOpacity, animationParameters.FadeTime)
                {
                    AutoReverse = false
                };

                fadeOutAnimation.Completed += (o, e) =>
                {
                    newImage.Opacity = 0d;
                    onChangeImage(newImage);
                    background.Opacity = animationParameters.TargetOpacity;
                    newImage.BeginAnimation(Brush.OpacityProperty, fadeInAnimation);
                };

                background.BeginAnimation(Brush.OpacityProperty, fadeOutAnimation);
            }
            else
            {
                newImage.Opacity = animateImageChangeParams.TargetOpacity;
                onChangeImage(newImage);
            }
        }
Example #3
0
 /// <summary>
 /// Animation fade in for the background of the grid container
 /// </summary>
 /// <param name="brush"></param>
 private void AnimateBackgroundFadeIn(ref ImageBrush brush)
 {
     if (!Container.Background.Equals(brush))
     {
         daFadeIn.From        = 0;
         daFadeIn.To          = 0.5;
         daFadeIn.Duration    = new Duration(TimeSpan.FromSeconds(2));
         Container.Background = brush;
         brush.BeginAnimation(ImageBrush.OpacityProperty, daFadeIn);
     }
 }
Example #4
0
        private void StartKenBurnsAnimation(Shape elementFadeIn)
        {
            ImageBrush brush = (ImageBrush)elementFadeIn.Fill;

            RectAnimation rectAnimation = new RectAnimation();

            rectAnimation.From           = _randomRects[_index];
            rectAnimation.To             = _randomRects[_index + 1];
            rectAnimation.Duration       = new Duration(TimeSpan.FromSeconds(30));
            rectAnimation.AutoReverse    = true;
            rectAnimation.RepeatBehavior = RepeatBehavior.Forever;
            Timeline.SetDesiredFrameRate(rectAnimation, 20);

            brush.BeginAnimation(TileBrush.ViewboxProperty, rectAnimation);
        }
Example #5
0
        private void IconGrid_Loaded(object sender, RoutedEventArgs e)
        {
            for (var i = 0; i < ColumnCount; i++)
            {
                ColumnDefinition columnDefinition = new ColumnDefinition();
                columnDefinition.Width = new GridLength(100.0 / ColumnCount, GridUnitType.Star);
                MainGrid.ColumnDefinitions.Add(columnDefinition);
            }

            for (var i = 0; i < RowCount; i++)
            {
                RowDefinition rowDefinition = new RowDefinition();
                rowDefinition.Height = new GridLength(100.0 / RowCount, GridUnitType.Star);
                MainGrid.RowDefinitions.Add(rowDefinition);
            }

            for (var i = 0; i < IconNames.Count; i++)
            {
                ImageBrush icon = FindResource(IconNames[i]) as ImageBrush;

                DoubleAnimation fade = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.1));
                fade.BeginTime = TimeSpan.FromSeconds(0.20 + i * 0.05);
                icon.BeginAnimation(ImageBrush.OpacityProperty, fade);

                Rectangle box = new Rectangle()
                {
                    Stroke = Brushes.White, StrokeThickness = 2, Opacity = 0.0,
                    Width  = IconWidth, Height = IconHeight, Fill = icon, Name = IconNames[i]
                };
                box.Margin = new Thickness(0, GrowthAmount, 0, GrowthAmount);

                DoubleAnimation appear = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.05));
                appear.BeginTime = TimeSpan.FromSeconds(i * 0.05);
                box.BeginAnimation(Rectangle.OpacityProperty, appear);

                box.MouseEnter          += Box_MouseEnter;
                box.MouseLeave          += Box_MouseLeave;
                box.MouseLeftButtonDown += Box_MouseLeftButtonDown;

                Grid.SetRow(box, i % 2);
                Grid.SetColumn(box, i / 2);

                MainGrid.Children.Add(box);
            }
        }
Example #6
0
        public void Activate()
        {
            for (var i = 0; i < IconNames.Count; i++)
            {
                ImageBrush icon = Images[i];

                DoubleAnimation fade = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.1));
                fade.BeginTime = TimeSpan.FromSeconds(0.20 + i * 0.05);
                icon.BeginAnimation(ImageBrush.OpacityProperty, fade);

                Rectangle box = new Rectangle()
                {
                    Stroke          = Brushes.White,
                    StrokeThickness = 2,
                    Opacity         = 0.0,
                    Width           = IconWidth,
                    Height          = IconHeight,
                    Fill            = icon,
                    Name            = IconNames[i]
                };
                box.Margin = new Thickness(0, _growth, 0, _growth);

                DoubleAnimation appear = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.05));
                appear.BeginTime = TimeSpan.FromSeconds(i * 0.05);
                box.BeginAnimation(Rectangle.OpacityProperty, appear);

                box.MouseEnter          += Box_MouseEnter;
                box.MouseLeave          += Box_MouseLeave;
                box.MouseLeftButtonDown += Box_MouseLeftButtonDown;

                Grid.SetRow(box, i % 2);
                Grid.SetColumn(box, i / 2);

                _boxes.Add(box);
            }
        }