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


C# TextBlock.Measure方法代码示例

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


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

示例1: MeasureTextSize

        public double MeasureTextSize(string text, double width, double fontSize, string fontName = null)
        {
            TextBlock tb = new TextBlock();

            if (fontName == null)
            {
                fontName = "Segoe UI";
            }

            tb.TextWrapping = TextWrapping.Wrap;
            tb.Text = text;
            tb.FontFamily = new Windows.UI.Xaml.Media.FontFamily(fontName);
            tb.FontSize = fontSize;
            tb.Measure(new Size(width, Double.PositiveInfinity));

            return tb.DesiredSize.Height + 5;
        }
开发者ID:alexrainman,项目名称:CarouselView,代码行数:17,代码来源:TextMeterImplementation.cs

示例2: TitleBarView

        public TitleBarView()
        {
            var settingsService = LazyResolver<ISettingsService>.Service;
            _textblock = new TextBlock
            {
                FontSize = 20,
                Foreground = new SolidColorBrush(Colors.Black),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(10, 0, 0, 0)
            };

            _redRect = new StackPanel
            {
                Height = 60,
                Width = 60,
                Background = new SolidColorBrush(Colors.Red)
            };

            _imagecategory = new Image
            {
                Height = 60,
                Width = 60
            };

            _textblock.Measure(new Size(0, 0));

            Height = 60;
            SetLeft(_textblock, _redRect.Width);
            SetTop(_textblock, (Height - _textblock.ActualHeight) / 2);
            Background=new SolidColorBrush(Colors.White);
            
            const string sourcelogo = "ms-appx:///Assets/logoIndiaRose.png";
            var logo = new Image
            {
                Source = new BitmapImage(new Uri(sourcelogo)),
                Width = 256
            };
            SetLeft(logo, LazyResolver<IScreenService>.Service.Width - logo.Width);

            Children.Insert(0, _imagecategory);
            Children.Insert(1, _textblock);
            Children.Insert(2, logo);

        }
开发者ID:india-rose,项目名称:xamarin-indiarose,代码行数:45,代码来源:TitleBarView.cs

示例3: InternalGetSize

 private Size InternalGetSize(char c, double fontSize, bool bold, bool italic)
 {
     var @event = new AutoResetEvent(false);
     var size = new Size();
     Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
             CoreDispatcherPriority.Normal,
             () => {
                 var textBlock = new TextBlock
                 {
                     Text = Convert.ToString(c),
                     FontSize = fontSize,
                     FontFamily = FontFamily,
                     FontStyle = italic ? FontStyle.Italic : FontStyle.Normal,
                     FontWeight = bold ? FontWeights.Bold : FontWeights.Normal
                 };
                 textBlock.Measure(new Size(1024.0, 1024.0));
                 size = new Size(textBlock.ActualWidth, textBlock.ActualHeight);
                 @event.Set();
             });
     @event.WaitOne();
     return size;
 }
开发者ID:Korshunoved,项目名称:Win10reader,代码行数:22,代码来源:FontHelper.cs

示例4: GenerateTaskPanel

        /// <summary>
        ///     Generates a new task panel
        /// </summary>
        /// <param name="cl">Class to generate it for</param>
        /// <param name="parent">ListView associated with the class</param>
        /// <param name="task">Task to add</param>
        /// <returns>A new ListViewItem for the task</returns>
        public static ListViewItem GenerateTaskPanel(Class cl, ListView parent, Task task)
        {
            #region Containers

            // Create the content area
            Grid content = new Grid
            {
                Margin = new Thickness(0),
                Height = 75,
                Background = MainPage.LightGrayBrush,
                Tag = "Task"
            };

            // Create the list of content items and a delegate to add them to the list
            List<UIElement> contentItems = new List<UIElement>();
            Action<UIElement> registerItem = i => { contentItems.Add(i); };

            // The main ListViewItem
            ListViewItem panel = new ListViewItem
            {
                Background = MainPage.TransparentBrush,
                Margin = new Thickness(0, 0, 0, 5),
                Height = 75,
                Tag = false, // Is Panel Expanded
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                VerticalContentAlignment = VerticalAlignment.Top,
                Padding = new Thickness(0),
                BorderBrush = MainPage.MediumGrayBrush,
                BorderThickness = new Thickness(1),
            };

            #endregion

            #region Title

            // Task title
            TextBlock title = new TextBlock
            {
                Text = task.Title.Trim(),
                TextAlignment = TextAlignment.Left,
                FontSize = 25,
                Foreground = MainPage.BlueBrush,
                Margin = new Thickness(5, 0, 0, 0)
            };
            // Sizing
            title.Measure(new Size(0, 0));
            title.Arrange(new Rect(0, 0, 0, 0));
            registerItem(title);

            #endregion

            #region Finish Button

            // The check mark that marks the task as completed
            Button finish = new Button
            {
                FontFamily = Icons.IconFont,
                Content = task.Complete == 1 ? Icons.Cancel : Icons.Accept,
                Margin = new Thickness(title.ActualWidth + 5, 5, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Background = MainPage.TransparentBrush
            };

            // Remove the task when the button is pressed
            finish.Tapped += (sender, args) => { TaskList.RemoveTask(cl, parent, panel, task); };
            registerItem(finish);

            #endregion

            #region Info Box

            // Info box
            TextBox info = new TextBox
            {
                TextAlignment = TextAlignment.Left,
                Foreground = new SolidColorBrush(Color.FromArgb(255, 50, 50, 50)),
                HorizontalAlignment = HorizontalAlignment.Left,
                TextWrapping = TextWrapping.Wrap,
                BorderThickness = new Thickness(0),
                AcceptsReturn = true,
                Width = parent.Width / 3 + 25,
                Tag = false, // Edit mode
                IsReadOnly = true, // Edit mode property
                Background = MainPage.TransparentBrush, // Edit mode property
                IsHitTestVisible = false // Edit mode property
            };

            // Add the text - only works if you append each character
            foreach (char c in task.Info)
            {
                info.Text += c.ToString();
            }
//.........这里部分代码省略.........
开发者ID:jkralicky,项目名称:TaskPlanner,代码行数:101,代码来源:TaskPanelFactory.cs

示例5: AddRangeCaption

        public void AddRangeCaption(LineConstraintRange range, string caption)
        {
            if (_rangeTxtMapping.ContainsKey(range))
                return;

            var txt = new TextBlock();
            txt.FontSize = 16;
            txt.Text = caption;
            txt.Measure(new Size(1000, 1000));

            Canvas.SetLeft(txt,
                range.Min*Canvas.ActualWidth + ((range.Max - range.Min)*Canvas.ActualWidth - txt.ActualWidth)/2);
            Canvas.SetTop(txt, 13);
            _rangeTxtMapping.Add(range, txt);

            DrawRanges();
        }
开发者ID:philllies,项目名称:finalproject,代码行数:17,代码来源:LineConstraint.xaml.cs

示例6: trimHeaderText

        private string trimHeaderText(string headerText, bool addIcon)
        {
            TextBlock textBlock = new TextBlock();
            textBlock.Text = headerText;
            textBlock.FontSize = GRID_HEADER_FONT_SIZE;

            if (addIcon)
            {
                Run text = new Run();
                text.Text = " \u25B2";
                textBlock.Inlines.Add(text);
            }

            textBlock.Measure(new Size(double.MaxValue, double.MaxValue));

            if(textBlock.ActualWidth > COLUMN_WIDTH - 10){
                while (textBlock.ActualWidth > COLUMN_WIDTH - 10)
                {
                    headerText = headerText.Remove(headerText.Length - 1).Trim();
                    textBlock.Text = String.Concat(headerText, "...");
                    if (addIcon)
                    {
                        Run text = new Run();
                        text.Text = " \u25B2";
                        textBlock.Inlines.Add(text);
                    }
                    textBlock.Measure(new Size(double.MaxValue, double.MaxValue));
                }
                headerText = String.Concat(headerText, "...");
            }

            return headerText;
        }
开发者ID:jwiese-ms,项目名称:hudl-win8,代码行数:33,代码来源:VideoPlayerView.xaml.cs

示例7: GetOWidth

 private double GetOWidth(ITextRenderAttributeState attributes, TextBlock r)
 {
     var key = GetCacheKey(new TextRenderCommand(attributes, new TextRenderTextContent("o")));
     if (!OWidthCache.ContainsKey(key))
     {
         var s2 = r.Text;
         r.Text = "o";
         r.Measure(new Size(0, 0));
         OWidthCache[key] = r.ActualWidth;
         r.Text = s2;
     }
     return OWidthCache[key];
 }
开发者ID:Opiumtm,项目名称:DvachBrowser3,代码行数:13,代码来源:RenderTextElementFactory.cs

示例8: DrawText

        /// <summary>
        /// The draw text.
        /// </summary>
        /// <param name="p">
        /// The p.
        /// </param>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="fontFamily">
        /// The font family.
        /// </param>
        /// <param name="fontSize">
        /// The font size.
        /// </param>
        /// <param name="fontWeight">
        /// The font weight.
        /// </param>
        /// <param name="rotate">
        /// The rotate.
        /// </param>
        /// <param name="halign">
        /// The horizontal alignment.
        /// </param>
        /// <param name="valign">
        /// The vertical alignment.
        /// </param>
        /// <param name="maxSize">
        /// The maximum size of the text.
        /// </param>
        public void DrawText(
            ScreenPoint p,
            string text,
            OxyColor fill,
            string fontFamily,
            double fontSize,
            double fontWeight,
            double rotate,
            OxyPlot.HorizontalAlignment halign,
            OxyPlot.VerticalAlignment valign,
            OxySize? maxSize)
        {
            var tb = new TextBlock { Text = text, Foreground = fill.ToBrush() };

            // tb.SetValue(TextOptions.TextHintingModeProperty, TextHintingMode.Animated);
            if (fontFamily != null)
            {
                tb.FontFamily = new FontFamily(fontFamily);
            }

            if (fontSize > 0)
            {
                tb.FontSize = fontSize;
            }

            tb.FontWeight = GetFontWeight(fontWeight);

            tb.Measure(new Size(1000, 1000));

            double dx = 0;
            if (halign == OxyPlot.HorizontalAlignment.Center)
            {
                dx = -tb.ActualWidth / 2;
            }

            if (halign == OxyPlot.HorizontalAlignment.Right)
            {
                dx = -tb.ActualWidth;
            }

            double dy = 0;
            if (valign == OxyPlot.VerticalAlignment.Middle)
            {
                dy = -tb.ActualHeight / 2;
            }

            if (valign == OxyPlot.VerticalAlignment.Bottom)
            {
                dy = -tb.ActualHeight;
            }

            var transform = new TransformGroup();
            transform.Children.Add(new TranslateTransform { X = (int)dx, Y = (int)dy });
            if (!rotate.Equals(0.0))
            {
                transform.Children.Add(new RotateTransform { Angle = rotate });
            }

            transform.Children.Add(new TranslateTransform { X = (int)p.X, Y = (int)p.Y });
            tb.RenderTransform = transform;

            if (this.clip.HasValue)
            {
                // add a clipping container that is not rotated
                var c = new Canvas();
                c.Children.Add(tb);
                this.Add(c);
//.........这里部分代码省略.........
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:101,代码来源:MetroRenderContext.cs

示例9: DrawLabels

        private void DrawLabels(TimeSeries ts)
        {
            Title.Text = ts.MetaData.Name;

            double priceOpen = ts.Values.First();
            double priceClose = ts.Values.Last();
            Value.Text = "  " + ts.Values.Last();
            var delta = (float)Math.Round(priceClose - priceOpen, 3);
            bool isNegative = delta < 0;
            Growth.Text = "   " + (!isNegative ? "+" : "") + delta;
            GrowthRate.Text = "   " + (!isNegative ? "+" : "") + Math.Round(delta / priceOpen, 3) * 100 + "%";
            Growth.Foreground = new SolidColorBrush(GetTrendColor(delta));
            GrowthRate.Foreground = new SolidColorBrush(GetTrendColor(delta));

            var labelOpen = new TextBlock();
            labelOpen.FontSize = 16;
            labelOpen.Text = ts.MetaData.Min.ToString();
            xCanvas.Children.Add(labelOpen);
            labelOpen.Measure(new Size(int.MaxValue, int.MaxValue));
            Canvas.SetTop(labelOpen, Height - 16);
            Canvas.SetLeft(labelOpen, -labelOpen.ActualWidth - 7);

            var labelClose = new TextBlock();
            labelClose.FontSize = 16;
            labelClose.Text = ts.MetaData.Max.ToString();
            xCanvas.Children.Add(labelClose);
            labelClose.Measure(new Size(int.MaxValue, int.MaxValue));
            Canvas.SetTop(labelClose, 2);
            Canvas.SetLeft(labelClose, -labelClose.ActualWidth - 7);

            var labelStartDate = new TextBlock();
            labelStartDate.FontSize = 16;
            labelStartDate.Text = "1";
            xCanvas.Children.Add(labelStartDate);
            Canvas.SetTop(labelStartDate, Height + 7);
            Canvas.SetLeft(labelStartDate, 0);

            var labelEndDate = new TextBlock();
            labelEndDate.FontSize = 16;
            labelEndDate.Text = ts.Values.Count.ToString();
            labelEndDate.Measure(new Size(int.MaxValue, int.MaxValue));
            xCanvas.Children.Add(labelEndDate);
            Canvas.SetTop(labelEndDate, Height + 7);
            Canvas.SetLeft(labelEndDate, Width - labelEndDate.ActualWidth);
        }
开发者ID:philllies,项目名称:finalproject,代码行数:45,代码来源:LineGraph.xaml.cs

示例10: BlockHeightOf

        private double BlockHeightOf( TextBlock t )
        {
            t.Measure( new Size( double.PositiveInfinity, double.PositiveInfinity ) );
            t.Arrange( new Rect( new Point(), t.DesiredSize ) );

            /* INTENSIVE_LOG
            if( t.FontSize == 16 )
            {
                Logger.Log( ID, string.Format( "FontSize 16 detected {0}, Should be {1}. Text {2}", t.FontSize, FontSize, t.Text ), LogType.DEBUG );
            }
            //*/

            return t.ActualHeight;
        }
开发者ID:tgckpg,项目名称:libpenguin,代码行数:14,代码来源:VerticalStack.cs

示例11: DrawLoadingMessage

        public void DrawLoadingMessage()
        {
            WaveCanvas.Children.Clear();

            double w = WaveCanvas.ActualWidth;
            double h = WaveCanvas.ActualHeight;

            TextBlock tbx = new TextBlock();
            tbx.FontSize = 16;
            tbx.Text = "Loading " + Utterance.AudioFile.Name;
            tbx.HorizontalAlignment = HorizontalAlignment.Center;
            tbx.VerticalAlignment = VerticalAlignment.Center;
            tbx.Foreground = new SolidColorBrush(Windows.UI.Colors.White);
            WaveCanvas.Children.Add(tbx);
            tbx.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            double tw = tbx.DesiredSize.Width;
            double th = tbx.DesiredSize.Height;
            Canvas.SetLeft(tbx, (w - tw) / 2.0);
            Canvas.SetTop(tbx, (h - th) / 2.0);
            tbx.Visibility = Visibility.Visible;
        }
开发者ID:david-wb,项目名称:Transcriber,代码行数:21,代码来源:AudioPlayer.cs

示例12: DrawGraph

        private void DrawGraph(TimeSeries timeSeriesData, TimeSeries ts)
        {
            double width = ActualWidth;
            double height = ActualHeight;

            TimeSeries tsn = ts.Clone();
            tsn.Normalize();

            DrawLine(0, 0, width, 0, 1f);
            DrawLine(width, 0, width, height, 1f);
            DrawLine(width, height, 0, height, 1f);
            DrawLine(0, height, 0, 0, 1f);

            int numLines = 3;
            float gap = (float) height/numLines;
            for (int i = 1; i < numLines; ++i)
            {
                DrawLine(0, (int) (i*gap), width, (int) (i*gap), 0.5f);
            }

            IList<double> values = tsn.Values;

            float w = ((float) width - 40)/values.Count;
            float h = (float) height - 40;

            for (int i = 1; i < values.Count; ++i)
            {
                var line = new Line
                {
                    X1 = 20 + (i - 1)*w,
                    Y1 = 20 + (1 - values[i - 1])*h,
                    X2 = 20 + i*w,
                    Y2 = 20 + (1 - values[i])*h,
                    StrokeThickness = 4,
                    StrokeEndLineCap = PenLineCap.Round,
                    Stroke = new SolidColorBrush(Colors.White)
                };

                LineGraphCanvas.Children.Add(line);
            }

            MathLine trend = tsn.GetTrend();
            var trendline = new Line
            {
                X1 = 20 + 0,
                Y1 = 20 + (1 - trend.GetY(0))*h,
                X2 = 20 + (values.Count - 1)*w,
                Y2 = 20 + (1 - trend.GetY(values.Count - 1))*h,
                StrokeThickness = 2.5,
                Stroke = new SolidColorBrush(GetTrendColor(trend.B))
            };

            LineGraphCanvas.Children.Add(trendline);

            Title.Text = timeSeriesData.Meta.Name;

            double priceOpen = ts.Values.First();
            double priceClose = ts.Values.Last();
            Value.Text = "  " + ts.Values.Last();
            var delta = (float) Math.Round(priceClose - priceOpen, 3);
            bool isNegative = delta < 0;
            Growth.Text = "   " + (!isNegative ? "+" : "") + delta;
            GrowthRate.Text = "   " + (!isNegative ? "+" : "") + Math.Round(delta/priceOpen, 3)*100 + "%";
            Growth.Foreground = new SolidColorBrush(GetTrendColor(delta));
            GrowthRate.Foreground = new SolidColorBrush(GetTrendColor(delta));

            var labelOpen = new TextBlock();
            labelOpen.FontSize = 16;
            labelOpen.Text = ts.Meta.Min.ToString();
            LineGraphCanvas.Children.Add(labelOpen);
            labelOpen.Measure(new Size(int.MaxValue, int.MaxValue));
            Canvas.SetTop(labelOpen, height - 16);
            Canvas.SetLeft(labelOpen, -labelOpen.ActualWidth - 7);

            var labelClose = new TextBlock();
            labelClose.FontSize = 16;
            labelClose.Text = ts.Meta.Max.ToString();
            LineGraphCanvas.Children.Add(labelClose);
            labelClose.Measure(new Size(int.MaxValue, int.MaxValue));
            Canvas.SetTop(labelClose, 2);
            Canvas.SetLeft(labelClose, -labelClose.ActualWidth - 7);

            var labelStartDate = new TextBlock();
            labelStartDate.FontSize = 16;
            labelStartDate.Text = "1";
            LineGraphCanvas.Children.Add(labelStartDate);
            Canvas.SetTop(labelStartDate, height + 7);
            Canvas.SetLeft(labelStartDate, 0);

            var labelEndDate = new TextBlock();
            labelEndDate.FontSize = 16;
            labelEndDate.Text = timeSeriesData.Values.Count.ToString();
            labelEndDate.Measure(new Size(int.MaxValue, int.MaxValue));
            LineGraphCanvas.Children.Add(labelEndDate);
            Canvas.SetTop(labelEndDate, height + 7);
            Canvas.SetLeft(labelEndDate, width - labelEndDate.ActualWidth);
        }
开发者ID:philllies,项目名称:finalproject,代码行数:97,代码来源:LineGraph.xaml.cs

示例13: temp

 private void temp()
 {
     MainGrid.Children.Clear();
     MainGrid.ColumnDefinitions.Clear();
     MainGrid.RowDefinitions.Clear();
     MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(CellWidth) });
     MainGrid.RowDefinitions.Add(new RowDefinition());
     TextBlock block = null;
     for (int x = 0; x < Columns.Count + 1; x++)
     {
         for (int y = 0; y < Rows.Count + 1; y++)
         {
             Rectangle rect = new Rectangle() { Fill = ((y) / 2 == (double)(y) / 2.0) ? new SolidColorBrush(Color.FromArgb(255, 56, 56, 56)) : new SolidColorBrush(Color.FromArgb(255, 64, 64, 64)), Margin = new Thickness(0,0,1,0) };
             Grid.SetColumn(rect, x);
             Grid.SetRow(rect, y);
             MainGrid.Children.Add(rect);
             if (x == 0)
             {
                 if (y > 0)
                 {
                     string rowTitle = Rows[y - 1];
                     MainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(CellHeight) });
                     bool sizeFound = false;
                     double candidateWidth = MainGrid.ColumnDefinitions[0].Width.Value;
                     double candidateHeight;
                     while (!sizeFound)
                     {
                         block = new TextBlock() { Text = rowTitle, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.WrapWholeWords, FontSize = 8, Margin = new Thickness(CellMargin) };
                         block.Measure(new Size(candidateWidth - CellMargin * 2, CellHeight * 2));
                         candidateHeight = block.ActualHeight;
                         block.Width = CellWidth;
                         if (candidateHeight <= CellHeight - CellMargin * 2)
                             sizeFound = true;
                         else
                             candidateWidth += 5;
                     }
                     block = new TextBlock() { Text = rowTitle, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.WrapWholeWords, FontSize = 8, Margin = new Thickness(CellMargin) };
                     MainGrid.ColumnDefinitions[0].Width = new GridLength(candidateWidth);
                     Grid.SetRow(block, y);
                     MainGrid.Children.Add(block);
                 }
             }
         }
         if (x > 0)
         {
             string columnTitle = Columns[x - 1];
             MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(CellWidth) });
             block = new TextBlock() { Text = columnTitle, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.WrapWholeWords, FontSize = 8, Margin = new Thickness(CellMargin) };
             Grid.SetColumn(block, x);
             MainGrid.Children.Add(block);
         }
     }
 }
开发者ID:AlexKven,项目名称:OneAppAway-RTM,代码行数:53,代码来源:DataGrid.xaml.cs

示例14: Create

        /// <summary>
        /// Создать элемент.
        /// </summary>
        /// <param name="command">Команда.</param>
        /// <returns>Элемент.</returns>
        public FrameworkElement Create(ITextRenderCommand command)
        {
            count++;
            string text;
            var textCnt = command.Content as ITextRenderTextContent;
            if (textCnt != null)
            {
                text = textCnt.Text ?? "";
            }
            else
            {
                text = "";
            }
            var r = new TextBlock()
            {
                Foreground = Application.Current.Resources["PostNormalTextBrush"] as Brush,
                TextWrapping = TextWrapping.NoWrap,
                TextTrimming = TextTrimming.None,
                FontSize = StyleManager.Text.PostFontSize,
                TextLineBounds = TextLineBounds.Full,
                IsTextSelectionEnabled = false,
                TextAlignment = TextAlignment.Left
            };

            FrameworkElement result = r;

            Border b = new Border();
            bool needBorder = false;

            Grid g = new Grid();
            bool needGrid = false;

            Grid g2 = new Grid();
            bool needOuterGrid = false;


            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Bold))
            {
                r.FontWeight = FontWeights.Bold;
            }
            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Italic))
            {
                r.FontStyle = FontStyle.Italic;
            }
            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Fixed))
            {
                r.FontFamily = new FontFamily("Courier New");
            }
            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Spoiler))
            {
                needBorder = true;
                b.Background = Application.Current.Resources["PostSpoilerBackgroundBrush"] as Brush;
                r.Foreground = Application.Current.Resources["PostSpoilerTextBrush"] as Brush;
            }
            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Quote))
            {
                r.Foreground = Application.Current.Resources["PostQuoteTextBrush"] as Brush;
            }
            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Link))
            {
                r.Foreground = Application.Current.Resources["PostLinkTextBrush"] as Brush;
            }

            b.BorderBrush = r.Foreground;
            b.BorderThickness = new Thickness(0);

            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Undeline) || command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Link))
            {
                needBorder = true;
                b.BorderThickness = new Thickness(b.BorderThickness.Left, b.BorderThickness.Top, b.BorderThickness.Right, 1.2);
            }
            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Overline))
            {
                needBorder = true;
                b.BorderThickness = new Thickness(b.BorderThickness.Left, 1.2, b.BorderThickness.Right, b.BorderThickness.Bottom);
            }

            Border strikeBorder = null;

            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Strikethrough))
            {
                needGrid = true;
                strikeBorder = new Border()
                {
                    Background = r.Foreground,
                    Height = 1.2,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment = VerticalAlignment.Top,
                };
                g.Children.Add(strikeBorder);
            }
            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Subscript) || command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Superscript))
            {
                needOuterGrid = true;
                r.Measure(new Size(0, 0));
//.........这里部分代码省略.........
开发者ID:Opiumtm,项目名称:DvachBrowser3,代码行数:101,代码来源:RenderTextElementFactory.cs

示例15: DrawGraph

        private void DrawGraph()
        {
            Line line;

            for (double xx = 0; xx < width; xx += zoom)
            {
                double x = xx + (width / 2 - xOffset);
                double x2 = (width / 2 - xOffset) - xx;

                line = new Line()
                {
                    X1 = x,
                    Y1 = -height / 2 + yOffset,
                    X2 = x,
                    Y2 = height + height / 2 + yOffset,
                    StrokeThickness = 1,
                    Stroke = new SolidColorBrush(Colors.Gray),
                    Opacity = 0.3
                };

                this.graphElements.Add(line);
                this.GraphCanvas.Children.Add(line);

                line = new Line()
                {
                    X1 = x2,
                    Y1 = -height / 2 + yOffset,
                    X2 = x2,
                    Y2 = height + height / 2 + yOffset,
                    StrokeThickness = 1,
                    Stroke = new SolidColorBrush(Colors.Gray),
                    Opacity = 0.3
                };

                this.graphElements.Add(line);
                this.GraphCanvas.Children.Add(line);

                if (xx / zoom != 0)
                {
                    TextBlock textBlock = new TextBlock();

                    textBlock.Text = "" + (-xx / zoom);
                    textBlock.Foreground = new SolidColorBrush(Colors.DarkTurquoise);
                    textBlock.FontSize = 20;

                    textBlock.Measure(new Size(10, 10));

                    Canvas.SetTop(textBlock, height / 2 + yOffset - textBlock.ActualHeight + 10);
                    Canvas.SetLeft(textBlock, x + textBlock.ActualWidth / 2);

                    textBlock.RenderTransform = new RotateTransform();

                    ((RotateTransform)textBlock.RenderTransform).Angle = 180;

                    this.graphElements.Add(textBlock);
                    this.GraphCanvas.Children.Add(textBlock);

                    textBlock = new TextBlock();

                    textBlock.Text = "" + (xx / zoom);
                    textBlock.Foreground = new SolidColorBrush(Colors.DarkTurquoise);
                    textBlock.FontSize = 20;

                    textBlock.Measure(new Size(10, 10));

                    Canvas.SetTop(textBlock, height / 2 + yOffset - textBlock.ActualHeight + 10);
                    Canvas.SetLeft(textBlock, x2 + textBlock.ActualWidth / 2);

                    textBlock.RenderTransform = new RotateTransform();

                    ((RotateTransform)textBlock.RenderTransform).Angle = 180;

                    this.graphElements.Add(textBlock);
                    this.GraphCanvas.Children.Add(textBlock);
                }
            }

            for (double yy = 0; yy < height; yy += zoom)
            {
                double y = yy + (height / 2 + yOffset);
                double y2 = (height / 2 + yOffset) - yy;

                line = new Line()
                {
                    X1 = -width / 2 - xOffset,
                    Y1 = y,
                    X2 = width + width / 2 - xOffset,
                    Y2 = y,
                    StrokeThickness = 1,
                    Stroke = new SolidColorBrush(Colors.Gray),
                    Opacity = 0.3
                };

                this.graphElements.Add(line);
                this.GraphCanvas.Children.Add(line);

                line = new Line()
                {
                    X1 = -width / 2 - xOffset,
                    Y1 = y2,
//.........这里部分代码省略.........
开发者ID:ConnorChristie,项目名称:Calculator,代码行数:101,代码来源:Graph.xaml.cs


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