コード例 #1
0
ファイル: RadRating.cs プロジェクト: zyhong/UI-For-UWP
        private static void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            RadRating rating = sender as RadRating;

            if (rating.settingValuePropertySilently)
            {
                return;
            }

            if (!rating.IsTemplateApplied)
            {
                return;
            }

            double oldValue = (double)args.OldValue;
            double newValue = RadMath.CoerceValue((double)args.NewValue, 0, rating.itemsSource.Count);

            if (newValue != rating.Value)
            {
                rating.SetValuePropertySilently(ValueProperty, newValue);
            }

            if (newValue != oldValue)
            {
                rating.HandleValueChange(oldValue, newValue);
            }
        }
コード例 #2
0
        /// <summary>
        /// Clips the <paramref name="rect"/> to the <paramref name="container"/>.
        /// </summary>
        /// <param name="rect">The <see cref="RadRect"/> to be clipped.</param>
        /// <param name="container">The container.</param>
        /// <param name="borderOverflow">The border (stroke thickness) of the <paramref name="rect"/>.</param>
        /// <param name="dashPatternLength">The length of the dash pattern of the <see cref="RadRect"/> stroke.</param>
        /// <returns>The clipped rectangle.</returns>
        internal static RadRect ClipRectangle(RadRect rect, RadRect container, double borderOverflow, double dashPatternLength)
        {
            // extend the container with the element border
            container.X      -= borderOverflow;
            container.Y      -= borderOverflow;
            container.Width  += 2 * borderOverflow;
            container.Height += 2 * borderOverflow;

            if (!rect.IntersectsWith(container))
            {
                return(RadRect.Empty);
            }

            // calculate the clipped rectangle, extended with the element border
            double xFrom = RadMath.CoerceValue(rect.X, container.X, container.Right);
            double yFrom = RadMath.CoerceValue(rect.Y, container.Y, container.Bottom);
            double xTo   = RadMath.CoerceValue(rect.Right, container.X, container.Right);
            double yTo   = RadMath.CoerceValue(rect.Bottom, container.Y, container.Bottom);

            if (dashPatternLength == 0 || double.IsNaN(dashPatternLength) || double.IsInfinity(dashPatternLength))
            {
                dashPatternLength = 1;
            }

            // first check if "To" values are clipped, and if so, add the additional space needed by the dash array to be rendered correctly
            if (rect.Right != xTo)
            {
                xTo += (rect.Right - xTo) % dashPatternLength;
            }

            if (rect.Bottom != yTo)
            {
                yTo += (rect.Bottom - yTo) % dashPatternLength;
            }

            // check if "From" values are clipped, and if so, add the additional space needed by the dash array to be rendered correctly and change the rect coordinates
            if (rect.X != xFrom)
            {
                xFrom -= (xFrom - rect.X) % dashPatternLength;
                rect.X = xFrom;
            }

            if (rect.Y != yFrom)
            {
                yFrom -= (yFrom - rect.Y) % dashPatternLength;
                rect.Y = yFrom;
            }

            rect.Width  = xTo - xFrom;
            rect.Height = yTo - yFrom;

            return(rect);
        }
コード例 #3
0
ファイル: RadRating.cs プロジェクト: zyhong/UI-For-UWP
        /// <inheritdoc/>
        protected override bool ApplyTemplateCore()
        {
            this.ratingPanel = this.GetTemplateChild("Part_RatingPanel") as StackPanel;
            if (this.ratingPanel == null)
            {
                throw new MissingTemplatePartException("Part_RatingPanel", typeof(StackPanel));
            }

            if (this.itemsSource.Count != 0)
            {
                if (!this.IsItemsSourceManual)
                {
                    throw new InvalidOperationException(AutoGeneratedItemsCountExceptionMessage);
                }

                this.SetValue(AutoGeneratedItemsCountProperty, 0);
            }
            else
            {
                if (this.AutoGeneratedItemsCount == (int)AutoGeneratedItemsCountProperty.GetMetadata(typeof(int)).DefaultValue)
                {
                    this.SetValue(AutoGeneratedItemsCountProperty, (int)AutoGeneratedItemsCountProperty.GetMetadata(typeof(int)).DefaultValue);
                }

                this.GenerateRatingItems();
            }

            this.PopulateRatingPanel();

            double coercedValue = RadMath.CoerceValue(this.Value, 0, this.itemsSource.Count);

            if (this.Value != coercedValue)
            {
                this.SetValuePropertySilently(ValueProperty, coercedValue);
            }

            double defaultValue = (double)ValueProperty.GetMetadata(typeof(double)).DefaultValue;

            if (this.Value != defaultValue)
            {
                this.HandleValueChange(defaultValue, this.Value);
            }

            this.UpdateDisplayValue();
            this.UpdateFillRatio();
            this.UpdateVisualState(false);

            return(base.ApplyTemplateCore());
        }
コード例 #4
0
        private static Point GetRestrictedDragPoint(DragVisualContext context, Point dragPoint, Point relativeStartPosition, Thickness maxPositionOffset)
        {
            double x = RadMath.CoerceValue(dragPoint.X - relativeStartPosition.X, -maxPositionOffset.Right, maxPositionOffset.Left);
            double y = RadMath.CoerceValue(dragPoint.Y - relativeStartPosition.Y, -maxPositionOffset.Bottom, maxPositionOffset.Top);

            switch (context.PositionRestriction)
            {
            case DragPositionMode.RailX:
                y = context.DragStartPosition.Y;
                break;

            case DragPositionMode.RailY:
                x = context.DragStartPosition.X;
                break;

            case DragPositionMode.RailXForward:
                y = context.DragStartPosition.Y;
                x = Math.Max(0, x);
                break;

            case DragPositionMode.RailXBackwards:
                y = context.DragStartPosition.Y;
                x = Math.Min(0, x);
                break;

            case DragPositionMode.RailYForward:
                x = context.DragStartPosition.X;
                y = Math.Max(0, y);
                break;

            case DragPositionMode.RailYBackwards:
                x = context.DragStartPosition.X;
                y = Math.Min(0, y);
                break;

            case DragPositionMode.Free:
            default:
                break;
            }

            return(new Point(x, y));
        }
コード例 #5
0
ファイル: RadRating.cs プロジェクト: zyhong/UI-For-UWP
        private static void OnAutoGeneratedItemsCountChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            RadRating rating = sender as RadRating;

            if (!rating.IsTemplateApplied)
            {
                return;
            }

            if ((int)args.OldValue == 0 && rating.itemsSource.Count != 0)
            {
                throw new InvalidOperationException(AutoGeneratedItemsCountExceptionMessage);
            }

            rating.isItemsSourceChangedSilently = true;
            rating.itemsSource.Clear();
            int newValue = (int)args.NewValue;

            if (newValue <= 0)
            {
                rating.AutoGeneratedItemsCount = 0;
            }
            else
            {
                rating.GenerateRatingItems();

                double coercedValue = RadMath.CoerceValue(rating.Value, 0, rating.itemsSource.Count);
                if (rating.Value != coercedValue)
                {
                    rating.SetValuePropertySilently(ValueProperty, coercedValue);
                    rating.UpdateDisplayValue();
                    rating.UpdateFillRatio();
                }
            }

            rating.isItemsSourceChangedSilently = false;
            rating.PopulateRatingPanel();
        }