Example #1
0
        private void AnimateFocusToCorner(object sender, DependencyPropertyChangedEventArgs e)
        {
            var element = (FrameworkElement)sender;

            if (element.Visibility != Visibility.Visible)
            {
                return;
            }
            element.Arrange(new Rect());

            FocusAnimationElement.Visibility = Visibility.Visible;
            var widthAnimation  = new DoubleAnimation(ActualWidth, element.ActualWidth, TimeSpan.FromSeconds(.3));
            var heightAnimation = new DoubleAnimation(ActualHeight, element.ActualHeight, TimeSpan.FromSeconds(.3));

            heightAnimation.Completed += (sender1, e1) => FocusAnimationElement.Visibility = Visibility.Collapsed;

            FocusAnimationElement.BeginAnimation(WidthProperty, widthAnimation);
            FocusAnimationElement.BeginAnimation(HeightProperty, heightAnimation);
        }
        private void DispatchAnimation(FrameworkElement element)
        {
            var point = element.TranslatePoint(new System.Windows.Point(), ContentPanel);

            FocusAnimationElement.Visibility      = Visibility.Visible;
            FocusAnimationElement.RenderTransform = new TranslateTransform();

            var xAnimation      = new DoubleAnimation(-ContentPanel.ActualWidth + point.X + element.ActualWidth, fastTime);
            var yAnimation      = new DoubleAnimation(point.Y, fastTime);
            var widthAnimation  = new DoubleAnimation(ContentPanel.ActualWidth, element.ActualWidth, fastTime);
            var heightAnimation = new DoubleAnimation(ContentPanel.ActualHeight, element.ActualHeight, fastTime);

            heightAnimation.Completed += (sender1, e1) => {
                FocusAnimationElement.Visibility      = Visibility.Collapsed;
                FocusAnimationElement.RenderTransform = null;
            };

            FocusAnimationElement.RenderTransform.BeginAnimation(TranslateTransform.XProperty, xAnimation);
            FocusAnimationElement.RenderTransform.BeginAnimation(TranslateTransform.YProperty, yAnimation);
            FocusAnimationElement.BeginAnimation(WidthProperty, widthAnimation);
            FocusAnimationElement.BeginAnimation(HeightProperty, heightAnimation);
        }