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


C# TextBlock.UpdateLayout方法代码示例

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


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

示例1: Draw

        internal void Draw()
        {
            if (!IsControlLaoded) return;

            //No cache for you gauge :( kill and redraw please
            foreach (var child in Canvas.Children
                .Where(x => !Equals(x, Stick) && !(x is AngularSection) && !(x is PieSlice)).ToArray())
                Canvas.Children.Remove(child);

            Wedge = Wedge > 360 ? 360 : (Wedge < 0 ? 0 : Wedge);

            var fromAlpha = (360-Wedge)*.5;
            var toAlpha = 360 - fromAlpha;

            var d = ActualWidth < ActualHeight ? ActualWidth : ActualHeight;

            Stick.Height = d*.5*.8;
            Stick.Width = Stick.Height*.2;

            Canvas.SetLeft(Stick, ActualWidth*.5 - Stick.Width*.5);
            Canvas.SetTop(Stick, ActualHeight*.5 - Stick.Height*.9);

            var ticksHi = d*.5;
            var ticksHj = d*.47;
            var labelsHj = d*.44;

            foreach (var section in Sections)
            {
                PieSlice slice;
                section.Owner = this;

                if (!Slices.TryGetValue(section, out slice))
                {
                    slice = new PieSlice();
                    Slices[section] = slice;
                }

                var p = (Canvas) section.Parent;
                p?.Children.Remove(section);
                Canvas.Children.Add(section);
                var ps = (Canvas) slice.Parent;
                ps?.Children.Remove(slice);
                Canvas.Children.Add(slice);
            }

            UpdateSections();

            for (var i = FromValue; i <= ToValue; i += TicksStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth*.5 + ticksHi*Math.Cos(alpha*Math.PI/180),
                    X2 = ActualWidth*.5 + ticksHj*Math.Cos(alpha*Math.PI/180),
                    Y1 = ActualHeight*.5 + ticksHi*Math.Sin(alpha*Math.PI/180),
                    Y2 = ActualHeight*.5 + ticksHj*Math.Sin(alpha*Math.PI/180)
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                    new Binding {Path = new PropertyPath("TicksForeground"), Source = this});
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath("TicksStrokeThickness"), Source = this });
            }

            for (var i = FromValue; i <= ToValue; i += LabelsStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth*.5 + ticksHi*Math.Cos(alpha*Math.PI/180),
                    X2 = ActualWidth*.5 + labelsHj*Math.Cos(alpha*Math.PI/180),
                    Y1 = ActualHeight*.5 + ticksHi*Math.Sin(alpha*Math.PI/180),
                    Y2 = ActualHeight*.5 + labelsHj*Math.Sin(alpha*Math.PI/180)
                };

                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = LabelFormatter(i)
                };

                //label.SetBinding(EffectProperty,
                    //new Binding {Path = new PropertyPath("LabelsEffect"), Source = this});

                Canvas.Children.Add(label);
                label.UpdateLayout();
                Canvas.SetLeft(label, alpha < 270
                    ? tick.X2
                    : (Math.Abs(alpha - 270) < 4
                        ? tick.X2 - label.ActualWidth*.5
                        : tick.X2 - label.ActualWidth));
                Canvas.SetTop(label, tick.Y2);
                tick.SetBinding(Shape.StrokeProperty,
                    new Binding { Path = new PropertyPath("TicksForeground"), Source = this });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath("TicksStrokeThickness"), Source = this });
            }
            MoveStick();
//.........这里部分代码省略.........
开发者ID:beto-rodriguez,项目名称:Live-Charts,代码行数:101,代码来源:AngularGauge.cs

示例2: DrawGraph

        /// <summary>
        /// Clears existing content then calculates new UI elements of the <see cref="Graph"/>
        /// for the current <see cref="BarometerTestUIModel.Graph"/>.
        /// </summary>
        private void DrawGraph()
        {
            // Initialize
            Graph.Children.Clear();

            // Calculate range and average
            var count = Model.Graph.Count;
            if (count == 0)
            {
                // Nothing to draw
                return;
            }
            var pressureMin = (double?)null;
            var pressureMax = (double?)null;
            var temperatureMin = (double?)null;
            var temperatureMax = (double?)null;
            var pressureTotal = (double?)null;
            var temperatureTotal = (double?)null;
            foreach (var point in Model.Graph)
            {
                var pressure = point.Pressure;
                if (!pressureMax.HasValue || pressure > pressureMax) pressureMax = pressure;
                if (!pressureMin.HasValue || pressure < pressureMin) pressureMin = pressure;
                pressureTotal = (pressureTotal ?? 0) + pressure;

                var temperature = point.Temperature;
                if (!temperatureMax.HasValue || temperature > temperatureMax) temperatureMax = temperature;
                if (!temperatureMin.HasValue || temperature < temperatureMin) temperatureMin = temperature;
                temperatureTotal = (temperatureTotal ?? 0) + temperature;
            }
            var pressureRange = (pressureMax ?? 0) - (pressureMin ?? 0);
            var pressureAverage = pressureTotal / count;
            var temperatureRange = (temperatureMax ?? 0) - (temperatureMin ?? 0);
            var temperatureAverage = temperatureTotal / count;

            // Calculate metrics
            Graph.UpdateLayout();
            var height = Graph.ActualHeight;
            var drawHeight = height - (GraphPadding * 2);
            var width = Graph.ActualWidth;
            var drawWidth = width - (GraphPadding * 2);
            var graphYMax = GraphPadding + drawHeight;
            Func<double, double, double, double> calculateGraphY = (double value, double minimum, double range) =>
            {
                if (range > 0)
                {
                    // Relative within range
                    return graphYMax - (drawHeight * ((value - minimum) / range));
                }
                else
                {
                    // Middle when flat line
                    return graphYMax - (drawHeight / 2);
                }
            };

            // Get resources
            var pressureBrush = (SolidColorBrush)Resources["GraphPressureBrush"];
            var temperatureBrush = (SolidColorBrush)Resources["GraphTemperatureBrush"];

            // Draw pressure average lines
            var pressureAverageY = calculateGraphY(pressureAverage.Value, pressureMin.Value, pressureRange);
            Graph.Children.Add(new Line
            {
                Stroke = pressureBrush,
                StrokeThickness = 1,
                X1 = GraphPadding,
                Y1 = pressureAverageY,
                X2 = GraphPadding + drawWidth,
                Y2 = pressureAverageY
            });

            // Draw temperature average line
            var temperatureAverageY = calculateGraphY(temperatureAverage.Value, temperatureMin.Value, temperatureRange);
            Graph.Children.Add(new Line
            {
                Stroke = temperatureBrush,
                StrokeThickness = 1,
                X1 = GraphPadding,
                Y1 = temperatureAverageY,
                X2 = GraphPadding + drawWidth,
                Y2 = temperatureAverageY
            });

            // Plot graph points
            var graphX = GraphPadding;
            var pressureLine = new Polyline
            {
                Stroke = pressureBrush,
                StrokeThickness = 1
            };
            var temperatureLine = new Polyline
            {
                Stroke = temperatureBrush,
                StrokeThickness = 1
            };
//.........这里部分代码省略.........
开发者ID:dpal887,项目名称:Navio-SDK-Windows-IoT,代码行数:101,代码来源:BarometerTest.xaml.cs


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