示例#1
0
        private void FlyOutSettingView(object o)
        {
            ColumnDefinition SettingCol   = _mainWindow.SettingCol;
            ColumnDefinition InfoCol      = _mainWindow.InfoCol;
            ColumnDefinition ModelViewCol = _mainWindow.ModelViewCol;

            ModelViewCol.Width = new GridLength(ModelViewCol.ActualWidth, GridUnitType.Pixel);

            GridLengthAnimation gla =
                new GridLengthAnimation
            {
                From         = new GridLength(SettingCol.ActualWidth, GridUnitType.Pixel),
                To           = new GridLength(0, GridUnitType.Star),
                Duration     = new TimeSpan(0, 0, 0, 0, 150),
                FillBehavior = FillBehavior.HoldEnd
            };

            //myanim.Completed += (s, e) =>
            //{
            //    //your completed action here
            //};

            GridLengthAnimation gla2 =
                new GridLengthAnimation
            {
                From         = new GridLength(InfoCol.ActualWidth, GridUnitType.Pixel),
                To           = new GridLength(SettingCol.ActualWidth, GridUnitType.Pixel),
                Duration     = new TimeSpan(0, 0, 0, 0, 150),
                FillBehavior = FillBehavior.HoldEnd
            };


            SettingCol.BeginAnimation(ColumnDefinition.WidthProperty, gla);
            InfoCol.BeginAnimation(ColumnDefinition.WidthProperty, gla2);
        }
示例#2
0
        public static void AnimateColumn(ColumnDefinition col, GridLength to, Action postAction = null)
        {
            var da = new GridLengthAnimation();

            da.Duration = TimeSpan.FromMilliseconds(300);

            da.From = col.Width;
            da.To   = to;

            //var ef = new BounceEase();
            //ef.EasingMode = EasingMode.EaseOut;
            //da.EasingFunction = ef;

            da.FillBehavior = FillBehavior.Stop;
            //col.Width = da.To;

            da.Completed += (s, e) =>
            {
                if (postAction != null)
                {
                    postAction();
                }
                else
                {
                    col.Width = to;
                }
            };

            col.BeginAnimation(ColumnDefinition.WidthProperty, da);
        }
示例#3
0
        private void AnimateMaxWidth(ColumnDefinition columnDefinition, double from, double to, double duration)
        {
            columnDefinition.BeginAnimation(ColumnDefinition.MaxWidthProperty, null);
            if (duration < MinimumDuration)
            {
                duration = MinimumDuration;
            }

            var storyboard = new Storyboard();

            var animationDuration = new Duration(TimeSpan.FromMilliseconds(duration));
            var ease = new CubicEase {
                EasingMode = EasingMode.EaseOut
            };

            var animation = new DoubleAnimation {
                EasingFunction = ease, Duration = animationDuration
            };

            storyboard.Children.Add(animation);
            animation.From = from;
            animation.To   = to;
            Storyboard.SetTarget(animation, columnDefinition);
            Storyboard.SetTargetProperty(animation, new PropertyPath("(ColumnDefinition.MaxWidth)"));

            storyboard.Completed += OnColumnMaxWidthAnimationCompleted;

            storyboard.Begin();
        }
        public static void AnimateTo(this ColumnDefinition column, double pixelValue, TimeSpan duration)
        {
            GridLengthAnimation widthAnim = new GridLengthAnimation()
            {
                To       = pixelValue,
                Duration = new Duration(duration)
            };

            column.BeginAnimation(ColumnDefinition.WidthProperty, widthAnim);
        }
示例#5
0
        public static void Anim(ColumnDefinition obj, double from, double to, DependencyProperty property, double time = 0.1)
        {
            var widthAnimation = new DoubleAnimation()
            {
                From     = from,
                To       = to,
                Duration = TimeSpan.FromSeconds(time),
            };

            obj.BeginAnimation(property, widthAnimation);
        }
        /// <summary>
        /// Animate expand/collapse of a grid column.
        /// </summary>
        /// <param name="gridColumn">The grid column to expand/collapse.</param>
        /// <param name="expandedWidth">The expanded width.</param>
        /// <param name="milliseconds">The milliseconds component of the duration.</param>
        /// <param name="collapsedWidth">The width when collapsed.</param>
        /// <param name="minWidth">The minimum width of the column.</param>
        /// <param name="seconds">The seconds component of the duration.</param>
        /// <param name="expand">If true, expand, otherwise collapse.</param>
        public static void AnimateGridColumnExpandCollapse(ColumnDefinition gridColumn, bool expand, double expandedWidth, double collapsedWidth,
                                                           double minWidth, TimeSpan duration)
        {
            if (expand && gridColumn.ActualWidth >= expandedWidth)
            {
                // It's as wide as it needs to be.
                return;
            }

            if (!expand && gridColumn.ActualWidth == collapsedWidth)
            {
                // It's already collapsed.
                return;
            }

            Storyboard storyBoard = new Storyboard();

            GridLengthAnimation animation = new GridLengthAnimation();

            animation.From     = new GridLength(gridColumn.ActualWidth);
            animation.To       = new GridLength(expand ? expandedWidth : collapsedWidth);
            animation.Duration = duration;

            // Set delegate that will fire on completion.
            animation.Completed += delegate
            {
                // Set the animation to null on completion. This allows the grid to be resized manually
                gridColumn.BeginAnimation(ColumnDefinition.WidthProperty, null);

                // Set the final value manually.
                gridColumn.Width = new GridLength(expand ? expandedWidth : collapsedWidth);

                // Set the minimum width.
                gridColumn.MinWidth = minWidth;
            };

            storyBoard.Children.Add(animation);

            Storyboard.SetTarget(animation, gridColumn);
            Storyboard.SetTargetProperty(animation, new PropertyPath(ColumnDefinition.WidthProperty));
            storyBoard.Children.Add(animation);

            // Begin the animation.
            storyBoard.Begin();
        }
示例#7
0
        private static void OnAttachGridAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                ColumnDefinition columndefinition = e.NewValue as ColumnDefinition;
                Button           btn = d as Button;
                btn.Click += (sender, routedeventargs) =>
                {
                    GridLengthAnimation animation = new GridLengthAnimation();
                    animation.From     = columndefinition.Width;
                    animation.To       = new GridLength(0.3, GridUnitType.Star);
                    animation.Duration = new Duration(TimeSpan.FromSeconds(0.5));

                    columndefinition.BeginAnimation(ColumnDefinition.WidthProperty, animation);
                };
            }
            catch { }
        }