wpf自定义标尺

Posted wrl_wuqingxue

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wpf自定义标尺相关的知识,希望对你有一定的参考价值。

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace PhotovolaticRadar.Client.Tools
{
    public class RadarTickBar: TickBar
    {
        protected override void OnRender(DrawingContext dc)
        {
            Double tickFrequencySize;
            Brush foreBrush = this.Fill;
            Pen line_Pen = new Pen(foreBrush, 1);

            FormattedText font = null;
            Size size = new Size(base.ActualWidth, base.ActualHeight);
            int tickCount = (int)((this.Maximum - this.Minimum) / this.TickFrequency) + 1;
            if ((this.Maximum - this.Minimum) % this.TickFrequency == 0)
                tickCount -= 1;
            tickFrequencySize = (size.Width * this.TickFrequency / (this.Maximum - this.Minimum));
            string text = "";
            double num = this.Maximum - this.Minimum;
            int i = 0;
            for (i = 0; i <= tickCount; i++)
            {
                if (i % 5 == 0)
                {
                    text = Convert.ToString(Convert.ToInt32(this.Minimum + this.TickFrequency * i), 10);
                    font = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 14, foreBrush);
                    dc.DrawText(font, new Point((tickFrequencySize * i), 20));
                    dc.DrawLine(line_Pen, new Point((tickFrequencySize * i), 44), new Point((tickFrequencySize * i), 64));
                }
                else
                {
                    dc.DrawLine(line_Pen, new Point((tickFrequencySize * i), 54), new Point((tickFrequencySize * i), 64));
                }
            }

        }
    }
}

  

以上是关于wpf自定义标尺的主要内容,如果未能解决你的问题,请参考以下文章

Android自定义View和属性动画完美结合,创造出酷炫圆环动画,带标尺和进度

Qt编写自定义控件45-柱状标尺控件

VSCode自定义代码片段——CSS选择器

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段(vue主模板)

VSCode自定义代码片段——声明函数