当前位置: 首页>>代码示例>>C#>>正文


C# Storyboard.AddAnimation方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Media.Animation.Storyboard.AddAnimation方法的典型用法代码示例。如果您正苦于以下问题:C# Storyboard.AddAnimation方法的具体用法?C# Storyboard.AddAnimation怎么用?C# Storyboard.AddAnimation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Media.Animation.Storyboard的用法示例。


在下文中一共展示了Storyboard.AddAnimation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdatePosition

        /// <summary>
        /// Update all positions. Launch every animations on all items with a unique StoryBoard
        /// </summary>
        private void UpdatePosition()
        {
            storyboard = new Storyboard();

            isUpdatingPosition = true;

            for (int i = 0; i < this.internalList.Count; i++)
            {
                // Do not animate all items
                var inf = this.SelectedIndex - (MaxVisibleItems * 2);
                var sup = this.SelectedIndex + (MaxVisibleItems * 2);

                if (i < inf || i > sup)
                    continue;

                var item = internalList[i];

                PlaneProjection planeProjection = item.Projection as PlaneProjection;

                if (planeProjection == null)
                    continue;

                // Get target projection
                var props = GetProjection(i, 0d);

                // Zindex and Opacity
                var deltaFromSelectedIndex = Math.Abs(this.SelectedIndex - i);
                int zindex = (this.internalList.Count * 100) - deltaFromSelectedIndex;
                Canvas.SetZIndex(item, zindex);

                Double opacity = 1d - (Math.Abs((Double)(i - this.SelectedIndex) / (MaxVisibleItems + 1)));

                var newVisibility = deltaFromSelectedIndex > MaxVisibleItems
                               ? Visibility.Collapsed
                               : Visibility.Visible;

                // Item already present
                if (item.Visibility == newVisibility && item.Visibility == Visibility.Visible)
                {
                    storyboard.AddAnimation(item, TransitionDuration, props.Item1, "(UIElement.Projection).(PlaneProjection.LocalOffsetX)", this.EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, props.Item2, "(UIElement.Projection).(PlaneProjection.GlobalOffsetY)", this.EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, props.Item3, "(UIElement.Projection).(PlaneProjection.GlobalOffsetZ)", this.EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, props.Item4, "(UIElement.Projection).(PlaneProjection.RotationY)", this.EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, opacity, "Opacity", this.EasingFunction);
                }
                else if (newVisibility == Visibility.Visible)
                {
                    // This animation will occur in the ArrangeOverride() method
                    item.Visibility = newVisibility;
                    item.Opacity = 0d;
                }
                else if (newVisibility == Visibility.Collapsed)
                {
                    storyboard.AddAnimation(item, TransitionDuration, 0d, "Opacity", this.EasingFunction);
                    storyboard.Completed += (sender, o) =>
                        item.Visibility = Visibility.Collapsed;
                }
            }

            // When storyboard completed, Invalidate
            storyboard.Completed += (sender, o) =>
            {
                this.isUpdatingPosition = false;
                this.InvalidateArrange();
            };

            storyboard.Begin();
        }
开发者ID:ZNTOAN,项目名称:LightStone,代码行数:71,代码来源:Carrousel.cs

示例2: UpdatePosition

        /// <summary>
        /// Update all positions. Launch every animations on all items with a unique StoryBoard.
        /// </summary>
        private void UpdatePosition()
        {
            var storyboard = new Storyboard();

            _isUpdatingPosition = true;

            for (var i = 0; i < _internalList.Count; i++)
            {
                // TODO optimize (x2 ?)
                // don't animate all items
                var inf = SelectedIndex - (MaxVisibleItems * 2);
                var sup = SelectedIndex + (MaxVisibleItems * 2);

                if (i < inf || i > sup)
                {
                    continue;
                }

                var item = _internalList[i];

                var planeProjection = item.Projection as PlaneProjection;
                if (planeProjection == null)
                {
                    continue;
                }

                // get target projection
                var props = GetProjection(i, 0d);

                // Zindex and Opacity
                var deltaFromSelectedIndex = Math.Abs(SelectedIndex - i);
                var zindex = (_internalList.Count * 100) - deltaFromSelectedIndex;
                SetZIndex(item, zindex);

                var opacity = 1d - (Math.Abs((double)(i - SelectedIndex) / (MaxVisibleItems + 1)));
                var newVisibility = deltaFromSelectedIndex > MaxVisibleItems ? Visibility.Collapsed : Visibility.Visible;

                // item already present
                if (item.Visibility == newVisibility && item.Visibility == Visibility.Visible)
                {
                    storyboard.AddAnimation(item, TransitionDuration, props.Item1, "(UIElement.Projection).(PlaneProjection.LocalOffsetX)", EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, props.Item2, "(UIElement.Projection).(PlaneProjection.GlobalOffsetY)", EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, props.Item3, "(UIElement.Projection).(PlaneProjection.GlobalOffsetZ)", EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, props.Item4, "(UIElement.Projection).(PlaneProjection.RotationY)", EasingFunction);
                    storyboard.AddAnimation(item, TransitionDuration, opacity, "Opacity", EasingFunction);
                }
                else switch (newVisibility)
                {
                    case Visibility.Visible:
                        // this animation will occur in the ArrangeOverride() method
                        item.Visibility = newVisibility;
                        item.Opacity = 0d;
                        break;
                    case Visibility.Collapsed:
                        storyboard.AddAnimation(item, TransitionDuration, 0d, "Opacity", EasingFunction);
                        storyboard.Completed += (sender, o) =>
                        {
                            item.Visibility = Visibility.Collapsed;
                        };
                        break;
                }
            }

            // start storyboard
            // when storyboard completed, InvalidateArrange()
            storyboard.Completed += (sender, o) =>
            {
                _isUpdatingPosition = false;
                InvalidateArrange();
            };
            storyboard.Begin();
        }
开发者ID:Biocodr,项目名称:HearthstoneCards,代码行数:75,代码来源:Caroussel.cs

示例3: ArrangeOverride

        /// <summary>
        /// Arrange all items
        /// </summary>
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (isUpdatingPosition)
                return finalSize;

            Double centerLeft = 0;
            Double centerTop = 0;

            this.Clip = new RectangleGeometry { Rect = new Rect(0, 0, finalSize.Width, finalSize.Height) };

            // Set
            Canvas.SetZIndex(rectangle, 1);

            // Storyboard for all Items to appear
            var localStoryboard = new Storyboard();

            for (int i = 0; i < this.internalList.Count; i++)
            {
                UIElement container = internalList[i];

                Size desiredSize = container.DesiredSize;
                if (double.IsNaN(desiredSize.Width) || double.IsNaN(desiredSize.Height)) continue;

                // get the good center and top position
                if (centerLeft == 0 && centerTop == 0 && desiredSize.Width > 0 && desiredSize.Height > 0)
                {
                    desiredWidth = desiredSize.Width;
                    desiredHeight = desiredSize.Height;

                    centerLeft = (finalSize.Width / 2) - (desiredWidth / 2);
                    centerTop = (finalSize.Height - desiredHeight) / 2;
                }

                // Get position from SelectedIndex
                var deltaFromSelectedIndex = Math.Abs(this.SelectedIndex - i);

                // Get rect position
                var rect = new Rect(centerLeft, centerTop, desiredWidth, desiredHeight);

                container.Arrange(rect);
                Canvas.SetLeft(container, centerLeft);
                Canvas.SetTop(container, centerTop);

                // Apply Transform
                PlaneProjection planeProjection = container.Projection as PlaneProjection;

                if (planeProjection == null)
                    continue;

                // Get an initial projection (without move)
                var props = GetProjection(i, 0d);

                planeProjection.LocalOffsetX = props.Item1;
                planeProjection.GlobalOffsetY = props.Item2;
                planeProjection.GlobalOffsetZ = props.Item3;
                planeProjection.RotationY = props.Item4;

                // calculate zindex and opacity
                int zindex = (this.internalList.Count * 100) - deltaFromSelectedIndex;
                double opacity = 1d - (Math.Abs((Double)(i - this.SelectedIndex) / (MaxVisibleItems + 1)));

                container.Opacity = opacity;
                // Item appears
                if (container.Visibility == Visibility.Visible && container.Opacity == 0d)
                    localStoryboard.AddAnimation(container, TransitionDuration, 0, opacity, "Opacity", this.EasingFunction);
                else
                    container.Opacity = opacity;

                Canvas.SetZIndex(container, zindex);

            }

            rectangle.Fill = new SolidColorBrush(Colors.Black);
            rectangle.Opacity = 0.9;
            Canvas.SetLeft(rectangle, 0);
            Canvas.SetTop(rectangle, (this.ActualHeight / 2));
            Canvas.SetZIndex(rectangle, 1);
            rectangle.Width = this.ActualWidth;
            rectangle.Height = this.ActualHeight;

            if (localStoryboard.Children.Count > 0)
                localStoryboard.Begin();

            return finalSize;
        }
开发者ID:ZNTOAN,项目名称:LightStone,代码行数:88,代码来源:Carrousel.cs

示例4: ArrangeOverride

        protected override Size ArrangeOverride(Size finalSize)
        {
            if (_isUpdatingPosition)
            {
                return finalSize;
            }

            var centerLeft = 0.0;
            var centerTop = 0.0;

            Clip = new RectangleGeometry { Rect = new Rect(0, 0, finalSize.Width, finalSize.Height) };

            // storyboard for all items to appear
            var localStoryboard = new Storyboard();
            for (var i = 0; i < _internalList.Count; i++)
            {
                var container = _internalList[i];

                var desiredSize = container.DesiredSize;
                if (double.IsNaN(desiredSize.Width) || double.IsNaN(desiredSize.Height))
                {
                    continue;
                }

                // get the good center and top position
                if (centerLeft == 0 && centerTop == 0 && desiredSize.Width > 0 && desiredSize.Height > 0)
                {
                    _desiredWidth = desiredSize.Width;
                    _desiredHeight = desiredSize.Height;

                    centerLeft = (finalSize.Width / 2) - (_desiredWidth / 2);
                    centerTop = (finalSize.Height - _desiredHeight) / 2;
                }

                // get delta position from SelectedIndex
                var deltaFromSelectedIndex = Math.Abs(SelectedIndex - i);

                // get rect position
                var rect = new Rect(centerLeft, centerTop, _desiredWidth, _desiredHeight);
                container.Arrange(rect);
                SetLeft(container, centerLeft);
                SetTop(container, centerTop);

                // get an initial projection (without move)
                // apply transformation
                var planeProjection = container.Projection as PlaneProjection;
                if (planeProjection == null)
                    continue;

                var props = GetProjection(i, 0d);
                planeProjection.LocalOffsetX = props.Item1;
                planeProjection.GlobalOffsetY = props.Item2;
                planeProjection.GlobalOffsetZ = props.Item3;
                planeProjection.RotationY = props.Item4;

                // calculate zindex and opacity
                var zindex = (_internalList.Count * 100) - deltaFromSelectedIndex;
                var opacity = 1d - (Math.Abs((double)(i - SelectedIndex) / (MaxVisibleItems + 1)));
                SetZIndex(container, zindex);
                container.Opacity = opacity;

                // item appearance
                if (container.Visibility == Visibility.Visible && container.Opacity == 0.0)
                {
                    localStoryboard.AddAnimation(container, TransitionDuration, 0, opacity, "Opacity", EasingFunction);
                }
                else
                {
                    container.Opacity = opacity;
                }
            }

            //rectangle.Fill = new SolidColorBrush(Colors.Black);
            //rectangle.Opacity = 0.9;
            //Canvas.SetLeft(rectangle, 0);
            //Canvas.SetTop(rectangle, (this.ActualHeight / 2));
            //Canvas.SetZIndex(rectangle, 1);
            //rectangle.Width = this.ActualWidth;
            //rectangle.Height = this.ActualHeight;

            // start storyboard
            if (localStoryboard.Children.Count > 0)
            {
                localStoryboard.Begin();
            }
            return finalSize;
        }
开发者ID:Biocodr,项目名称:HearthstoneCards,代码行数:87,代码来源:Caroussel.cs


注:本文中的Windows.UI.Xaml.Media.Animation.Storyboard.AddAnimation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。