当前位置: 首页>>代码示例>>C#>>正文


C# Line.Measure方法代码示例

本文整理汇总了C#中Line.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# Line.Measure方法的具体用法?C# Line.Measure怎么用?C# Line.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Line的用法示例。


在下文中一共展示了Line.Measure方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        private void Initialize()
        {
            double desiredWidth = 0;
            CalculateAutoInterval();
            GenerateLabels();
            if (this.ActualHeight > 0 && this.ActualWidth > 0)
            {

                this.Children.Clear();
                double yAxisHeightStep = this.ActualHeight / ((MIntervalCount > 0) ? MIntervalCount : 1);
                double yAxisHeightPosition = this.DataToPoint(MStartValue);
                Rect oldRect = new Rect(0, 0, 0, 0);
                AxisLine = new Line();
                Binding binding = new Binding();
                binding.Path = new PropertyPath("AxisLineStyle");
                binding.Source = this;
                AxisLine.SetBinding(Line.StyleProperty, binding);
                AxisLine.X1 = this.ActualWidth;
                AxisLine.X2 = this.ActualWidth;
                AxisLine.Y1 = 0;
                AxisLine.Y2 = this.ActualHeight;
                AxisLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
                Labels = new List<ContentControl>();
                MajorTickLines = new List<Line>();
                MinorTickLines = new List<Line>();
                double labelSize = 0;
                for (int i = this.MLabels.Count - 1; i >= 0; i--)
                {
                    ContentControl label = new ContentControl();
                    label.Content = MLabels[i];
                    //label.ContentTemplate = this.LabelTemplate;
                    Binding labelTemplateBinding = new Binding();
                    labelTemplateBinding.Path = new PropertyPath("LabelTemplate");
                    labelTemplateBinding.Source = this;
                    label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding);
                    label.Measure(new Size(this.ActualHeight, this.ActualWidth));
                    RotateTransform labelRotation = new RotateTransform();
                    labelRotation.Angle = LabelAngle;
                    Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation);
                    label.RenderTransform = labelRotation;
                    Labels.Add(label);
                    Line tickLine = new Line();
                    double labelPadding = 0;
                    Binding styleBinding = new Binding();
                    styleBinding.Path = new PropertyPath("MajorLineStyle");
                    styleBinding.Source = this;
                    tickLine.SetBinding(Line.StyleProperty, styleBinding);
                    //tickLine.Style = MajorLineStyle;
                    tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));

                    tickLine.Y1 = yAxisHeightPosition;
                    tickLine.Y2 = yAxisHeightPosition;

                    switch (MajorTicksPosition)
                    {
                        case TickPosition.Inside:
                            tickLine.X1 = this.ActualWidth;
                            tickLine.X2 = tickLine.X1 + MajorLineSize;
                            if (this.ShowMajorTicks)
                            {
                                labelPadding = 0;
                                desiredWidth = 0;
                            }
                            break;
                        case TickPosition.Cross:
                            tickLine.X1 = this.ActualWidth -(MajorLineSize / 2);
                            tickLine.X2 = this.ActualWidth + (MajorLineSize / 2);
                            if (this.ShowMajorTicks)
                            {
                                labelPadding = tickLine.X2;
                                desiredWidth = this.MajorLineSize / 2;
                            }
                            break;
                        case TickPosition.Outside:
                            tickLine.X1 = this.ActualWidth;
                            tickLine.X2 = tickLine.X1 - MajorLineSize;
                            if (this.ShowMajorTicks)
                            {
                                labelPadding = tickLine.X2;
                                desiredWidth = this.MajorLineSize;
                            }
                            break;
                        default:
                            break;
                    }
                    Binding ticklineVisibilityBinding = new Binding();
                    ticklineVisibilityBinding.Path = new PropertyPath("ShowMajorTicks");
                    ticklineVisibilityBinding.Source = this;
                    ticklineVisibilityBinding.Converter = new BooleanToVisibilityConverter();
                    tickLine.SetBinding(Line.VisibilityProperty, ticklineVisibilityBinding);
                    MajorTickLines.Add(tickLine);
                    this.Children.Add(tickLine);
                    //desiredWidth = 0;
                    double minorstep = 0;
                    if (!(i == 0))
                    {
                        double minorWidth = yAxisHeightStep;
                        minorstep = minorWidth / (MinorTicksCount + 1);
                        for (int j = 0; j < this.MinorTicksCount; j++)
                        {
//.........这里部分代码省略.........
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:101,代码来源:YAxis.cs

示例2: Update

        /// <summary>
        /// Updates this instance.
        /// </summary>
        internal void Update()
        {
            double desiredWidth = 0;
            CalculateAutoInterval();
            GenerateLabels();
            if (this.ActualHeight > 0 && this.ActualWidth > 0)
            {
                double yAxisHeightStep = this.ActualHeight / ((MIntervalCount > 0) ? MIntervalCount : 1);
                double yAxisHeightPosition = 0;
                Rect oldRect = new Rect(0, 0, 0, 0);
                AxisLine.X1 = this.ActualWidth;
                AxisLine.X2 = this.ActualWidth;
                AxisLine.Y1 = 0;
                AxisLine.Y2 = this.ActualHeight;
                Binding binding = new Binding();
                binding.Path = new PropertyPath("AxisLineStyle");
                binding.Source = this;
                AxisLine.SetBinding(Line.StyleProperty, binding);
                double labelSize = 0;
                int minorCount = 0;
                if (this.MLabels.Count == Labels.Count)
                {
                    for (int i = this.MLabels.Count - 1; i >=0; i--)
                    {
                        yAxisHeightPosition = this.DataToPoint(MLabelValues[i]);
                        ContentControl label = Labels[i];
                        label.Content = MLabels[i];
                        label.Measure(new Size(this.ActualHeight, this.ActualWidth));
                        RotateTransform labelRotation = new RotateTransform();
                        labelRotation.Angle = LabelAngle;
                        Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation);
                        label.RenderTransform = labelRotation;
                        Line tickLine = MajorTickLines[i];
                        double labelPadding = 0;
                        tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
                        //tickLine.X1 = this.ActualWidth;
                        tickLine.Y1 = yAxisHeightPosition;
                        tickLine.Y2 = yAxisHeightPosition;
                        //tickLine.X2 = tickLine.X1 - MajorLineSize;
                        switch (MajorTicksPosition)
                        {
                            case TickPosition.Inside:
                                tickLine.X1 = this.ActualWidth;
                                tickLine.X2 = tickLine.X1 + MajorLineSize;
                                if (this.ShowMajorTicks)
                                {
                                    labelPadding = 0;
                                    desiredWidth = 0;
                                }
                                break;
                            case TickPosition.Cross:
                                tickLine.X1 = this.ActualWidth - (MajorLineSize / 2);
                                tickLine.X2 = this.ActualWidth + (MajorLineSize / 2);
                                if (this.ShowMajorTicks)
                                {
                                    labelPadding = tickLine.X2;
                                    desiredWidth = this.MajorLineSize / 2;
                                }
                                break;
                            case TickPosition.Outside:
                                tickLine.X1 = this.ActualWidth;
                                tickLine.X2 = tickLine.X1 - MajorLineSize;
                                if (this.ShowMajorTicks)
                                {
                                    labelPadding = tickLine.X2;
                                    desiredWidth = this.MajorLineSize;
                                }
                                break;
                            default:
                                break;
                        }
                        //desiredWidth = 0;
                        if (i != 0)
                        {
                            double minorWidth = yAxisHeightStep;
                            double minorstep = minorWidth / (MinorTicksCount + 1);
                            for (int j = 0; j < this.MinorTicksCount; j++)
                            {
                                Line minorLine = MinorTickLines[minorCount];
                                minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1));
                                minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1));
                                //minorLine.X1 = this.ActualWidth - (minorLine.StrokeThickness);
                               // minorLine.X2 = minorLine.X1 - MinorLineSize;
                                switch (MinorTicksPosition)
                                {
                                    case TickPosition.Inside:
                                        minorLine.X1 = this.ActualWidth;
                                        minorLine.X2 = minorLine.X1 + MinorLineSize;
                                        break;
                                    case TickPosition.Cross:
                                        minorLine.X1 = this.ActualWidth - (MinorLineSize / 2);
                                        minorLine.X2 = this.ActualWidth + (MinorLineSize / 2);
                                        break;
                                    case TickPosition.Outside:
                                        minorLine.X1 = this.ActualWidth;
                                        minorLine.X2 = minorLine.X1 - MinorLineSize;
                                        break;
//.........这里部分代码省略.........
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:101,代码来源:YAxis.cs

示例3: Update

        /// <summary>
        /// Updates this instance.
        /// </summary>
        internal void Update()
        {
            double desiredHeight = 0;
            double labelSize = 0;
            CalculateAutoInterval();
            GenerateLabels();
            if (this.ActualHeight > 0 && this.ActualWidth > 0)
            {
                double xAxisWidthStep = this.ActualWidth / ((MIntervalCount > 0) ? MIntervalCount : 1);
                double xAxisWidthPosition = 0;
                double minorstep = 0;
                AxisLine.X2 = this.ActualWidth;
                Rect oldRect = new Rect(0, 0, 0, 0);

                if (this.MLabels.Count == Labels.Count)
                {
                    int k = 0;
                    int minorCount = 0;
                    for (int i = 0; i < this.MLabels.Count; i++)
                    {
                        xAxisWidthPosition = this.DataToPoint(MStartValue + (MInterval * k));
                        ContentControl label = Labels[k];
                        label.Content = MLabels[k];
                        label.Measure(new Size(this.ActualHeight, this.ActualWidth));
                        RotateTransform labelRotation = new RotateTransform();
                        labelRotation.Angle = LabelAngle;
                        Rect originalRect=new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height);

                        Rect rotatedRect = GetRotatedRect(originalRect, labelRotation);
                        //label.RenderTransformOrigin = new Point(0.5, 0.5);
                        label.RenderTransform = labelRotation;
                        Line tickLine = MajorTickLines[k];
                        double labelPadding = 0;
                        tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
                        tickLine.X1 = xAxisWidthPosition ;
                        tickLine.X2 = xAxisWidthPosition ;
                        switch (MajorTicksPosition)
                        {
                            case TickPosition.Inside:
                                if (this.ShowMajorTicks)
                                {
                                    labelPadding = 0;
                                    desiredHeight = 0;
                                }
                                break;
                            case TickPosition.Cross:
                                if (this.ShowMajorTicks)
                                {
                                    labelPadding = tickLine.Y2;
                                    desiredHeight = tickLine.Y2;
                                }
                                break;
                            case TickPosition.Outside:
                                if (this.ShowMajorTicks)
                                {
                                    labelPadding = tickLine.Y2;
                                    desiredHeight = tickLine.Y2;
                                }
                                break;
                            default:
                                break;
                        }
                        if (!(i == this.MLabels.Count - 1))
                        {
                            double minorWidth = xAxisWidthStep;
                            minorstep = minorWidth / (MinorTicksCount + 1);
                            for (int j = 0; j < this.MinorTicksCount; j++)
                            {
                                Line minorLine = MinorTickLines[minorCount];
                                minorLine.X1 = (xAxisWidthPosition + minorstep * (j + 1));
                                minorLine.X2 = (xAxisWidthPosition + minorstep * (j + 1));
                                switch (MinorTicksPosition)
                                {
                                    case TickPosition.Inside:
                                        minorLine.Y1 = 0;
                                        break;
                                    case TickPosition.Cross:
                                        //minorLine.Y1 = MinorLineSize / 2;
                                        break;
                                    case TickPosition.Outside:
                                        minorLine.Y1 = 0;
                                        break;
                                    default:
                                        break;
                                }

                                minorCount++;
                            }
                        }

                        //Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2));
                        //Canvas.SetTop(label, desiredHeight);
                        if (this.LabelAngle == 0)
                        {
                            Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2));
                            Canvas.SetTop(label, desiredHeight);
                            labelSize = Math.Max(labelSize, label.DesiredSize.Height);
//.........这里部分代码省略.........
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:101,代码来源:XAxis.cs

示例4: MeasureOverride

        protected override Size MeasureOverride(Size availableSize)
        {
            if (_hasViewChanged)
            {
                // In determining the number of guidelines to display, it must be kept in mind that
                // the spacings between the lines might be variable depending on the
                // current time unit. For instance, if the timeline is measured in months, then the
                // lines will not be equally spaced apart because a month is anywhere from 28 to 31 days.
                // The solution is to produce lines one at a time while the total accumulated width is
                // less than the viewport width.
                //
                // 1. First we first convert the current horizontal offset into a TimeSpan, and add
                // that to the timeline's start time to get the time of the viewport's left edge. This
                // time may be more precise than the timeline's current unit of measurement. For
                // example, the viewport left time may be defined down to the second, but the timeline's
                // unit is an hour. Therefore, we must round up to the nearest unit.
                //
                // 2. The difference between the rounded date and the precise date is the time between
                // the start of the viewport and the initial line. Converting this TimeSpan into pixels
                // will yield the x position of the initial line relative to the viewport's left edge.
                // We can store this value along with the line number for use during the arranging process.
                //
                // 3. Now we can create a guideline, add it to the panel, and measure it.
                //
                // 4. Next we increment the rounded date by whatever is set as the timeline's unit.
                //
                // 5. Repeat steps 2 to 4 until the rounded date is equal to or exceeds the date of the
                // viewport's right edge.

                Children.Clear();

                if (_lineOffsets == null)
                {
                    _lineOffsets = new Dictionary<int, double>();
                }
                else
                {
                    _lineOffsets.Clear();
                }

                ExtendedDateTime viewportLeftTime = Dates.Earliest() + Ruler.ToTimeSpan(_horizontalOffset);
                ExtendedDateTime viewportRightTime = Dates.Earliest() + Ruler.ToTimeSpan(_horizontalOffset + availableSize.Width);
                ExtendedDateTime guidelineTime = null;
                int guidelineIndex = 0;

                switch (Resolution)
                {
                    case TimeResolution.Century:
                        guidelineTime = new ExtendedDateTime(viewportLeftTime.Year - viewportLeftTime.Year % 100 + 100);
                        break;

                    case TimeResolution.Decade:
                        guidelineTime = new ExtendedDateTime(viewportLeftTime.Year - viewportLeftTime.Year % 10 + 10);
                        break;

                    case TimeResolution.Year:
                        guidelineTime = viewportLeftTime.ToRoundedPrecision(ExtendedDateTimePrecision.Year, true);
                        break;

                    case TimeResolution.Month:
                        guidelineTime = viewportLeftTime.ToRoundedPrecision(ExtendedDateTimePrecision.Month, true);
                        break;

                    case TimeResolution.Day:
                        guidelineTime = viewportLeftTime.ToRoundedPrecision(ExtendedDateTimePrecision.Day, true);
                        break;

                    case TimeResolution.Hour:
                        guidelineTime = viewportLeftTime.ToRoundedPrecision(ExtendedDateTimePrecision.Hour, true);
                        break;

                    case TimeResolution.Minute:
                        guidelineTime = viewportLeftTime.ToRoundedPrecision(ExtendedDateTimePrecision.Minute, true);
                        break;

                    case TimeResolution.Second:
                        guidelineTime = viewportLeftTime.ToRoundedPrecision(ExtendedDateTimePrecision.Second, true);
                        break;

                    default:
                        break;
                }

                while (guidelineTime < viewportRightTime)
                {
                    var guideline = new Line();
                    guideline.Y2 = availableSize.Height;
                    guideline.StrokeThickness = 1;
                    guideline.UseLayoutRounding = true;
                    guideline.SnapsToDevicePixels = true;

                    switch (Resolution)
                    {
                        case TimeResolution.Century:
                            _lineOffsets.Add(guidelineIndex, Ruler.ToPixels(viewportLeftTime, guidelineTime));
                            guideline.Stroke = guidelineTime.Year % (100 * MajorFrequency) == 0 ? MajorBrush : MinorBrush;
                            guidelineTime = guidelineTime.AddYears(100);
                            break;

                        case TimeResolution.Decade:
//.........这里部分代码省略.........
开发者ID:nharren,项目名称:MusicTimeline,代码行数:101,代码来源:GuidelinePanel.cs

示例5: Initialize

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        internal void Initialize()
        {
            double desiredHeight = 0;
            double labelSize = 0;
            //if (m_MinValue == m_startValue + m_Interval)
            CalculateAutoInterval();
            GenerateLabels();
            if (this.ActualHeight > 0 && this.ActualWidth > 0)
            {

                this.Children.Clear();
                double xAxisWidthStep = this.ActualWidth / ((MIntervalCount > 0) ? MIntervalCount : 1);
                double xAxisWidthPosition = this.DataToPoint(MStartValue);
                double minorstep = 0;
                //m_offset = this.DataToPoint(m_MinValue + m_Interval);
                Rect oldRect = new Rect(0, 0, 0, 0);
                AxisLine = new Line();
                AxisLine.X1 = 0;
                AxisLine.X2 = this.ActualWidth;
                AxisLine.Y1 = 0;
                AxisLine.Y2 = 0;
                Binding binding = new Binding();
                binding.Path = new PropertyPath("AxisLineStyle");
                binding.Source = this;
                AxisLine.SetBinding(Line.StyleProperty, binding);
                Labels = new List<ContentControl>();
                MajorTickLines = new List<Line>();
                MinorTickLines = new List<Line>();
                for (int i = 0; i < this.MLabels.Count; i++)
                {
                    ContentControl label = new ContentControl();
                    label.Content = MLabels[i];
                    Binding labelTemplateBinding = new Binding();
                    labelTemplateBinding.Path = new PropertyPath("LabelTemplate");
                    labelTemplateBinding.Source = this;
                    label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding);
                    label.Measure(new Size(this.ActualHeight, this.ActualWidth));
                    RotateTransform labelRotation = new RotateTransform();
                    labelRotation.Angle = LabelAngle;
                    Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation);
                    //label.RenderTransformOrigin = new Point(0.5, 0.5);
                    label.RenderTransform = labelRotation;
                    Labels.Add(label);

                    Line tickLine = new Line();
                    double labelPadding = 0;
                    Binding styleBinding = new Binding();
                    styleBinding.Path = new PropertyPath("MajorLineStyle");
                    styleBinding.Source = this;
                    tickLine.SetBinding(Line.StyleProperty, styleBinding);
                    tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
                    tickLine.X1 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2);
                    tickLine.X2 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2);

                    switch (this.MajorTicksPosition)
                    {
                        case TickPosition.Inside:
                            tickLine.Y1 = 0;
                            Binding tickSizeInsideBinding = new Binding();
                            tickSizeInsideBinding.Path = new PropertyPath("MajorLineSize");
                            tickSizeInsideBinding.Source = this;
                            tickSizeInsideBinding.Converter = new NegativeConverter();
                            tickLine.SetBinding(Line.Y2Property, tickSizeInsideBinding);
                            if (this.ShowMajorTicks)
                            {
                                labelPadding = 0;
                                desiredHeight = 0;
                            }
                            break;
                        case TickPosition.Cross:
                            Binding tickSizeNegativeCrossBinding = new Binding();
                            tickSizeNegativeCrossBinding.Path = new PropertyPath("MajorLineSize");
                            tickSizeNegativeCrossBinding.Source = this;
                            tickSizeNegativeCrossBinding.Converter = new NegativeHalfConverter();
                            tickLine.SetBinding(Line.Y1Property, tickSizeNegativeCrossBinding);

                            Binding tickSizeCrossBinding = new Binding();
                            tickSizeCrossBinding.Path = new PropertyPath("MajorLineSize");
                            tickSizeCrossBinding.Source = this;
                            tickSizeCrossBinding.Converter = new HalfValueConverter();
                            tickLine.SetBinding(Line.Y2Property, tickSizeCrossBinding);
                            if (this.ShowMajorTicks)
                            {
                                labelPadding = tickLine.Y2;
                                desiredHeight = MajorLineSize / 2;
                            }
                            break;
                        case TickPosition.Outside:
                            tickLine.Y1 = 0;
                            Binding tickSizeBinding = new Binding();
                            tickSizeBinding.Path = new PropertyPath("MajorLineSize");
                            tickSizeBinding.Source = this;
                            tickLine.SetBinding(Line.Y2Property, tickSizeBinding);
                            if (this.ShowMajorTicks)
                            {
                                labelPadding = tickLine.Y2;
                                desiredHeight = MajorLineSize;
//.........这里部分代码省略.........
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:101,代码来源:XAxis.cs


注:本文中的Line.Measure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。