コード例 #1
0
        private static void TransformerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PathListBoxItemTransformer transformer = (PathListBoxItemTransformer)d;

            if (transformer != null && transformer.pathLayoutItem != null && transformer.pathListBox != null)
            {
                transformer.UpdateTransform();
            }
        }
コード例 #2
0
        private void UpdateTransform()
        {
            if (this.pathListBox == null)
            {
                this.pathListBox = PathListBoxItemTransformer.FindAncestor <PathListBox>(this);
                if (this.pathListBox == null)
                {
                    return;
                }
            }

            if (this.pathLayoutItem == null)
            {
                this.pathLayoutItem = PathListBoxItemTransformer.FindAncestor <IPathLayoutItem>(this);
                if (this.pathLayoutItem == null)
                {
                    return;
                }
                this.pathLayoutItem.PathLayoutUpdated += this.IPathLayoutItem_PathLayoutUpdated;
            }

            double offset = 0;

            if (this.UseGlobalOffset)
            {
                offset = this.pathLayoutItem.GlobalOffset;
            }
            else
            {
                offset = this.pathLayoutItem.LocalOffset;
            }

            offset = (offset + Math.Abs(this.Shift)) % 1;

            int zIndex          = 0;
            int layoutPathIndex = -1;

            zIndex          = this.pathLayoutItem.LocalIndex;
            layoutPathIndex = this.pathLayoutItem.LayoutPathIndex;

            // Adjust the offset so that it is normalized over a range of -1 to 1 if falloff from center.
            if (this.IsCentered)
            {
                offset = Math.Abs(PathListBoxItemTransformer.Lerp(-1, 1, (offset + 0.5) % 1.0));
                int numItems = this.pathListBox.GetItemsArrangedCount(layoutPathIndex) / 2;
                zIndex = (int)Math.Round(offset * numItems);
            }

            UIElement element = this.pathLayoutItem as UIElement;

            if (element != null && Canvas.GetZIndex(element) != zIndex)
            {
                Canvas.SetZIndex(element, (int)zIndex);
            }

            // Adjust the offset by the user specified easing function.
            if (this.Ease != null)
            {
                offset = this.Ease.Ease(offset);
            }

            // Check value before setting it to avoid layout cycle exceptions.
            if (this.AdjustedOffset != offset)
            {
                this.AdjustedOffset = offset;
            }

            // Use the adjusted offset to interpolate between the user specified start and end for scale and opacity.
            double scale = 1;

            scale = PathListBoxItemTransformer.Lerp(this.ScaleRange.X, this.ScaleRange.Y, this.AdjustedOffset);
            ScaleTransform scaleTransform = (ScaleTransform)this.transformGroup.Children[0];

            scaleTransform.ScaleX = scale;
            scaleTransform.ScaleY = scale;

            double          angle           = PathListBoxItemTransformer.Lerp(this.AngleRange.X, this.AngleRange.Y, this.AdjustedOffset) + this.pathLayoutItem.OrientationAngle;
            RotateTransform rotateTransform = (RotateTransform)this.transformGroup.Children[1];

            rotateTransform.Angle = angle;

            this.Opacity = PathListBoxItemTransformer.Lerp(this.OpacityRange.X, this.OpacityRange.Y, this.AdjustedOffset);
        }