Beispiel #1
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            var animationClock = GetAnimationClock (this);

            StopClock();

            var count = Children.Count;
            if (count == 0)
            {
                return finalSize;
            }

            var previewWidth = PreviewWidth;
            var adjustedSize = new Size (
                Math.Max (finalSize.Width - (count - 1) * previewWidth, previewWidth),
                finalSize.Height
                );
            var adjustedRect = adjustedSize.ToRect();

            var activeElement = ActiveElement;

            var desiredX = 0.0;

            var doAnimate = false;

            for (int index = 0; index < count; index++)
            {
                var child = Children[index];

                var state = GetChildState(child);
                if (state == null)
                {
                    state = new State
                                {
                                    Transform   = new TranslateTransform(),
                                    From        = finalSize.Width,
                                    To          = finalSize.Width,
                                };
                    SetChildState (child, state);
                }

                child.Arrange(adjustedRect);
                child.RenderTransform = state.Transform;

                var current = state.GetCurrentX (animationClock);

                state.From  = current;
                state.To    = desiredX;

                state.UpdateTransform (current);

                doAnimate |= !state.From.IsNear (state.To);

                if (ReferenceEquals (child, activeElement))
                {
                    desiredX += adjustedSize.Width;
                }
                else
                {
                    desiredX += previewWidth;
                }
            }

            if (doAnimate)
            {
                StartClock();
            }

            return finalSize;
        }