Example #1
0
        public ColorLabel(string text, double lineHeight, RedlineSide side)
        {
            this.InitializeComponent();

            _side = side;

            if (side == RedlineSide.Bottom)
            {
                BottomTextBlock.Text  = text;
                BottomVerticalLine.Y2 = lineHeight;
            }
            else
            {
                TopTextBlock.Text            = text;
                TopHorizontalLine.Y1         = -lineHeight;
                TopHorizontalLine.Y2         = TopHorizontalLine.Y1;
                TopTextBlock.RenderTransform = new TranslateTransform()
                {
                    Y = -lineHeight
                };
                TopVerticalLine.Y1 = -lineHeight;
            }

            Loaded += ColorLabel_Loaded;
        }
Example #2
0
        private void AddRedline(double x, double y, RedlineSide side, double value, Canvas target, int depth, FrameworkElement fe, string propertyName)
        {
            DebugSpaces(depth);
            Debug.WriteLine(fe.Name + "." + propertyName + " = " + value);

            double addedSpace = _redlineCount[(int)side] * _redlineSpace;
            double size       = _redlineMinSize + addedSpace;

            GeneralTransform t = fe.TransformToVisual(target);

            Windows.Foundation.Point pos = t.TransformPoint(new Windows.Foundation.Point(0, 0));

            switch (side)
            {
            case RedlineSide.Left:
                x    -= addedSpace;
                size += pos.X - _controlPos.X;
                break;

            case RedlineSide.Top:
                y    -= addedSpace;
                size += pos.Y - _controlPos.Y;
                break;

            case RedlineSide.Right:
                x += addedSpace;
                double extendX = (_controlPos.X + _control.ActualWidth) - (pos.X + fe.ActualWidth);
                x    -= extendX;
                size += extendX;
                break;

            case RedlineSide.Bottom:
                y += addedSpace;
                double extendY = (_controlPos.Y + _control.ActualHeight) - (pos.Y + fe.ActualHeight);
                y    -= extendY;
                size += extendY;
                break;
            }

            Redline redline = new Redline(side, size, value);

            Canvas.SetLeft(redline, x);
            Canvas.SetTop(redline, y);

            target.Children.Add(redline);
        }
Example #3
0
        private void DrawColorLabels()
        {
            RedlineSide   redlineSide   = RedlineSide.Top;
            double        redlineHeight = 20;
            List <double> xPositions    = new List <double>();

            // Reverse sort by x, draw the lines from right to left to avoid line corssing
            redlineInfos.Sort((a, b) => b.TargetHorizontalCenter().X.CompareTo(a.TargetHorizontalCenter().X));
            for (int i = 0; i < redlineInfos.Count; i++)
            {
                var redline  = redlineInfos[i];
                var label    = new ColorLabel(redline.Content, redlineHeight, redlineSide);
                var position = redline.TargetHorizontalCenter();
                var x        = position.X;

                // Make sure labels are not too close to each other
                if (i >= 2)
                {
                    // We switch side(top/bottom) for each draw, [i-2] is the previous redline thats on the same side.
                    var previousX = xPositions[i - 2];
                    if (x > previousX || Math.Abs(x - previousX) < 5)
                    {
                        x = previousX - 5;
                    }
                }

                xPositions.Add(x);
                Canvas.SetLeft(label, x);
                Canvas.SetTop(label, redlineSide == RedlineSide.Bottom ? position.Y + redline.TargetHeight : position.Y);
                RedlineCanvas.Children.Add(label);

                // Flip drawing position and grow redline height to avoid overlapping
                if (redlineSide == RedlineSide.Top)
                {
                    redlineSide = RedlineSide.Bottom;
                }
                else
                {
                    redlineSide    = RedlineSide.Top;
                    redlineHeight += 30;
                }
            }
        }
Example #4
0
        public Redline(RedlineSide side, double size, double value)
        {
            this.InitializeComponent();

            _side = side;

            if (IsHorizontal())
            {
                Width = value;
                if (_side == RedlineSide.Top)
                {
                    HorizontalBottomRow.Height = new GridLength(size);
                }
                else
                {
                    HorizontalTopRow.Height = new GridLength(size);
                }
            }
            else
            {
                Height = value;
                if (_side == RedlineSide.Left)
                {
                    VerticalRightRow.Width = new GridLength(size);
                }
                else
                {
                    VerticalLeftRow.Width = new GridLength(size);
                }
            }

            HorizontalLabel.Text = value.ToString();
            VerticalLabel.Text   = value.ToString();

            Loaded += Redline_Loaded;
        }