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


C# ContentControl.Measure方法代码示例

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


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

示例1: Measure_Should_Call_Child_Measure

        public void Measure_Should_Call_Child_Measure()
        {
            ContentControl target = new ContentControl();
            ChildControl child = new ChildControl();

            child.RecordInputs = true;
            target.Content = child;           
            target.Measure(new Size(12, 23));

            Assert.AreEqual(new Size(12, 23), child.MeasureInput);
        }
开发者ID:modulexcite,项目名称:Avalonia,代码行数:11,代码来源:ContentControl_MeasureArrangeTests.cs

示例2: Template_Should_Be_Instantiated

        public void Template_Should_Be_Instantiated()
        {
            using (var ctx = RegisterServices())
            {
                var target = new ContentControl();
                target.Content = "Foo";
                target.Template = GetTemplate();

                target.Measure(new Size(100, 100));

                var child = ((IVisual)target).VisualChildren.Single();
                Assert.IsType<Border>(child);
                child = child.VisualChildren.Single();
                Assert.IsType<ContentPresenter>(child);
                child = child.VisualChildren.Single();
                Assert.IsType<TextBlock>(child);
            }
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:18,代码来源:ContentControlTests.cs

示例3: 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

示例4: 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

示例5: 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

示例6: 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


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