コード例 #1
0
ファイル: VerticalIndicator.cs プロジェクト: Mrding/Ribbon
        protected override void OnRender(DrawingContext dc)
        {
            dc.DrawRectangle(Brushes.Transparent, null, new Rect(0, 0, RenderSize.Width, RenderSize.Height));

            if (_currentPoint == null) return;

            if (_lines == null || 0 == _lines.Count) return;

            var count = _lines.Count;

            var mouse = _currentPoint.Value;

            _valueIndex = GetCurrentIndex(mouse);

            if (_valueIndex < 0) return;

            if (_pen == null)
            {
                _pen = this.GetDashPen(Brushes.DarkGray);
                _pen.Freeze();
            }

            var height = RenderSize.Height - 20; // 20 上方日期占位

            var values = new Dictionary<double, string>();

            for (var i = 0; i < count; i++)
            {
                if (_lines[i].SaftyGetProperty<bool, ISelectable>(l => l.IsSelected != true))
                    continue;

                var value = CalibrateValue(_lines[i].Values[_valueIndex]);
                if (value == 0) continue;

                if (values.ContainsKey(value))
                    continue;

                var y = CalibrateAxisY(value, height);

                values[value] = string.Format(_lines[i].Format, value);

                values[value].ToFormattedText(Brushes.Black).Self(fTxt =>
                {
                    fTxt.SetFontSize(10);
                    dc.PushEffect(_effect, null);
                    dc.DrawText(fTxt, new Point(mouse.X + 3, height - y));
                    dc.Pop();
                });
            }

            if (values.Count == 0) return;

            //mouse.X + .5 校正
            dc.DrawLine(_pen, new Point(mouse.X + .5, 0), new Point(mouse.X + .5, this.RenderSize.Height));

            _pointDateTime.ToString("hh:mm").ToFormattedText(Brushes.Black).Self(fTxt =>
            {
                dc.DrawText(fTxt, new Point(mouse.X - 32, RenderSize.Height - 18));
            });
        }