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


C# TextBlock.UpdateLayout方法代码示例

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


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

示例1: Draw

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

            //No cache for you gauge :( kill and redraw please
            foreach (var child in Canvas.Children.Cast<UIElement>()
                .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;
                if (p != null) p.Children.Remove(section);
                Canvas.Children.Add(section);
                var ps = (Canvas)slice.Parent;
                if (ps != null) 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(TicksForegroundProperty), Source = this});
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath(TicksStrokeThicknessProperty), 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(LabelsEffectProperty), 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(TicksForegroundProperty), Source = this });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this });
            }
//.........这里部分代码省略.........
开发者ID:beto-rodriguez,项目名称:Live-Charts,代码行数:101,代码来源:AngularGauge.cs

示例2: InsertLineCenteredText

		TextBlock InsertLineCenteredText (Canvas FramingCanvas, String Text,
							double FontSizePercentage, double TopPercentage,
							String Weight, String Color)
			{
			FontWeightConverter FWConverter = new FontWeightConverter ();
			BrushConverter BRConverter = new BrushConverter ();
			TextBlock BlockName = new TextBlock ();
			BlockName.Visibility = Visibility.Visible;
			FramingCanvas.Children.Add (BlockName);
			FramingCanvas.UpdateLayout ();
			double ActCanvasHeight = FramingCanvas.ActualHeight;
			double ActCanvasWidth = FramingCanvas.ActualWidth;
			BlockName.FontSize = FontSizePercentage * ActCanvasHeight / 100;
			BlockName.FontWeight = (FontWeight)FWConverter.ConvertFromString (Weight);
			BlockName.Foreground = (Brush)BRConverter.ConvertFromString (Color);
			BlockName.Text = Text;
			BlockName.TextAlignment = TextAlignment.Center;
			BlockName.UpdateLayout ();
			double ActHeadHeight = BlockName.ActualHeight;
			double ActHeadWidth = BlockName.ActualWidth;
			Canvas.SetTop (BlockName, (ActCanvasHeight * TopPercentage) / 100);
			Canvas.SetLeft (BlockName, ((ActCanvasWidth - ActHeadWidth) / 2));
			return BlockName;
			}
开发者ID:heinzsack,项目名称:DEV,代码行数:24,代码来源:WPMediaRunWeatherDisplayControl.xaml.cs

示例3: InsertCanvasPositionedTextBlock

		public TextBlock InsertCanvasPositionedTextBlock (Canvas FramingCanvas, String Text,
						double WidthPercentage, double HeightPercentage,
						double FontSizePercentage, double LeftPercentage,
						double TopPercentage, String Weight, String Color)
			{
			FontWeightConverter FWConverter = new FontWeightConverter ();
			BrushConverter BRConverter = new BrushConverter ();
			TextBlock BlockName = new TextBlock ();
			BlockName.Visibility = Visibility.Visible;
			FramingCanvas.Children.Add (BlockName);
			FramingCanvas.UpdateLayout ();
			double ActCanvasHeight = FramingCanvas.ActualHeight;
			if (ActCanvasHeight == 0)
				ActCanvasHeight = FramingCanvas.Height;
			double ActCanvasWidth = FramingCanvas.ActualWidth;
			if (ActCanvasWidth == 0)
				ActCanvasWidth = FramingCanvas.Width;
			Canvas.SetTop (BlockName, ((ActCanvasHeight * TopPercentage) / 100));
			Canvas.SetLeft (BlockName, ((ActCanvasWidth * LeftPercentage) / 100));
			double BlockNameWidth = (ActCanvasWidth * WidthPercentage) / 100;
			double BlockNameHeight = (ActCanvasHeight * HeightPercentage) / 100;
			Text = Text.Replace ("\r\n", " ");
			Text = Text.Replace ("\n", " ");
			Text = Text.Replace ("\r", " ");
			bool TextFit = false;
			double FontReduction = 1;
			while (!TextFit)
				{
				BlockName.FontSize = (ActCanvasHeight * FontSizePercentage / 100.0) * FontReduction;
				BlockName.FontWeight = (FontWeight)FWConverter.ConvertFromString (Weight);
				if (Color.IndexOf ('$') == -1)
					BlockName.Foreground = (Brush)BRConverter.ConvertFromString (Color);
				else
					BlockName.Foreground = (Brush)BRConverter.ConvertFromString (Color);
				BlockName.TextAlignment = TextAlignment.Left;
				BlockName.TextWrapping = TextWrapping.Wrap;
				BlockName.Text = Text;
				BlockName.UpdateLayout ();
				double ActTextHeight = BlockName.ActualHeight;
				double ActTextWidth = BlockName.ActualWidth;
				double NumberOfPossibleLines = (double)((int)(BlockNameHeight / ActTextHeight));
				double RequiredNumberOfLines = (ActTextWidth * 1.10) / BlockNameWidth;
				if (RequiredNumberOfLines < NumberOfPossibleLines)
					{
					TextFit = true;
					}
				FontReduction -= 0.05;
				if (FontReduction < 0.30)
					TextFit = true;
				}

			BlockName.Width = BlockNameWidth;
			BlockName.Height = BlockNameHeight;
			return BlockName;
			}
开发者ID:heinzsack,项目名称:DEV,代码行数:55,代码来源:XAMLHandling.cs

示例4: InsertCanvasPositionedText

		TextBlock InsertCanvasPositionedText (Canvas FramingCanvas, String Text,
							double WidthPercentage, double HeightPercentage,
							double FontSizePercentage, String Weight, String Color)
			{
			FontWeightConverter FWConverter = new FontWeightConverter ();
			BrushConverter BRConverter = new BrushConverter ();
			TextBlock BlockName = new TextBlock ();
			BlockName.Visibility = Visibility.Visible;
			FramingCanvas.Children.Add (BlockName);
			double ActCanvasHeight = FramingCanvas.ActualHeight;
			double ActCanvasWidth = FramingCanvas.ActualWidth;
			BlockName.FontSize = ActCanvasHeight * FontSizePercentage / 100.0;
			BlockName.FontWeight = (FontWeight)FWConverter.ConvertFromString (Weight);
			BlockName.Foreground = (Brush)BRConverter.ConvertFromString (Color);
			BlockName.Text = Text;
			BlockName.TextAlignment = TextAlignment.Center;
			BlockName.UpdateLayout ();
			double ActTextHeight = BlockName.ActualHeight;
			double ActTextWidth = BlockName.ActualWidth;
			Canvas.SetTop (BlockName, (((ActCanvasHeight * HeightPercentage) / 100) - (ActTextHeight / 2)));
			Canvas.SetLeft (BlockName, (((ActCanvasWidth * WidthPercentage) / 100) - (ActTextWidth / 2)));
			return BlockName;
			}
开发者ID:heinzsack,项目名称:DEV,代码行数:23,代码来源:WPMediaRunWeatherDisplayControl.xaml.cs

示例5: SetContent

 private void SetContent(TextBlock textblock, string text)
 {
     textblock.Text = text;
     textblock.UpdateLayout();
 }
开发者ID:BigBri41,项目名称:TWCTVWindowsPhone,代码行数:5,代码来源:VideoPlayerCaptionBlockRegion.cs


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