public void NullifyFontFamily () { LineBreak lb = new LineBreak (); lb.FontFamily = null; // note: Trying to readback FontFamily, after setting it to null, will crash the plugin // see Run.NullifyFontFamily for a more dramatic effect ;-) }
public void FindName () { LineBreak lb = new LineBreak (); Assert.Throws<ArgumentNullException> (delegate { lb.FindName (null); }, "null"); Assert.IsNull (lb.FindName (String.Empty), "Empty"); }
/// <summary> /// 本方法使用多个Run以及LineBreak对象来创建文本。 /// 本添加到StackPanel complexTBPlaceHolder中去. /// </summary> private void CreateComplexTextBlock() { TextBlock complexTextBlock = new TextBlock(); Run paragraph1 = new Run() { Text = "Paragraph1" }; LineBreak lineBreak = new LineBreak(); Run paragraph2 = new Run() { Text = "Paragraph2" }; complexTextBlock.Inlines.Add(paragraph1); complexTextBlock.Inlines.Add(lineBreak); complexTextBlock.Inlines.Add(paragraph2); this.complexTBPlaceHolder.Children.Add(complexTextBlock); }
/// <summary> /// 本项目创建一个文本对象,并用外部字体, /// 创建完成后添加到StackPanel customizeFormatPlaceHolder中去. /// </summary> private void FormatText() { TextBlock formatTextBlock = new TextBlock(); Run paragraph1 = new Run() { Text = "Paragraph1" }; paragraph1.FontFamily = new FontFamily("Magnetob.ttf#Magneto"); LineBreak lineBreak = new LineBreak(); Run paragraph2 = new Run() { Text = "Paragraph2" }; LinearGradientBrush brush = new LinearGradientBrush(); brush.GradientStops.Add(new GradientStop() { Color = Colors.Blue, Offset = 0d }); brush.GradientStops.Add(new GradientStop() { Color = Colors.Red, Offset = 1d }); paragraph2.Foreground = brush; formatTextBlock.Inlines.Add(paragraph1); formatTextBlock.Inlines.Add(lineBreak); formatTextBlock.Inlines.Add(paragraph2); this.customizeFormatPlaceHolder.Children.Add(formatTextBlock); }
private void CreateButtonNewGame(Grid grid) { btnNewGame = new Button(); btnNewGame.FontSize = 22; btnNewGame.Click += new RoutedEventHandler(btnNewGame_Click); var txtNewGame = new TextBlock(); LineBreak br = new LineBreak(); txtNewGame.Inlines.Add("Nuevo"); txtNewGame.Inlines.Add(br); txtNewGame.Inlines.Add("Juego"); btnNewGame.Content = txtNewGame; //btnNewGame.Content = "Nuevo Juego"; Grid.SetColumn(btnNewGame, 1); grid.Children.Add(btnNewGame); }
protected override void Append(LoggingEvent logging) { if (TextBox == null) { return; } TextBox.Dispatcher.Invoke(() => { TextPointer position = TextBox.CaretPosition.DocumentEnd; var lineBreak = new LineBreak(position); var text = new Run(mLayout.Format(logging), position); text.Foreground = COLORS[logging.Level]; TextBox.ScrollToEnd(); }); }
/// <summary> /// Renders the specified chat node to the client. /// </summary> /// <param name="node">The node to append.</param> /// <remarks> /// <para>The return value of this function is a reference to the outermost <see cref="Inline">Inline</see> constructed /// by this function. It may create additional inner elements as needed.</para> /// </remarks> /// <returns> /// Returns an object instance of <see cref="Inline">Inline</see> that can be appended to the HTML document. /// </returns> public virtual Inline Render(ChatNode node) { Inline result; if (node == ChatNode.NewLine) { result = new LineBreak(); } else if (node.LinkUri == null) { Run run = new Run(); if (node.CssClass != null) { run.Style = ResourceProvider[node.CssClass] as Style; run.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass); } else if (node.Color != GdiColor.Empty) { run.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, node.Color.R, node.Color.G, node.Color.B)); } run.Text = node.Text; result = run; } else // need to make a link. { Hyperlink link = new Hyperlink(); link.Inlines.Add(new Run(node.Text)); link.NavigateUri = node.LinkUri; if (node.CssClass != null) { link.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass); } else if (node.Color != GdiColor.Empty) { link.Foreground = new SolidColorBrush(WpfColor.FromArgb(255, node.Color.R, node.Color.G, node.Color.B)); } link.ToolTip = string.Format(CultureInfo.CurrentUICulture, "Link to {0}", node.LinkUri.ToString()); result = link; } return result; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.CardImage = ((System.Windows.Controls.Image)(target)); return; case 2: this.CardTitle = ((System.Windows.Controls.Label)(target)); return; case 3: this.CardDescription = ((System.Windows.Documents.LineBreak)(target)); return; case 4: this.showMore = ((System.Windows.Controls.Button)(target)); return; } this._contentLoaded = true; }
public void AddString(String text, CharDisplayInfo cdi) { if (text == "") return; _parent.Dispatcher.Invoke(new Action(delegate { if (text == "\r\n") { if (_p.Inlines.LastInline is LineBreak && _p.Inlines.LastInline.PreviousInline is LineBreak) { return; } LineBreak lb = new LineBreak(); _p.Inlines.Add(lb); _currentRun = null; return; } if (currentStyle != cdi.Style) { currentStyle = cdi.Style; _currentRun = new Run(); _p.Inlines.Add(_currentRun); if ((cdi.Style & ZStyles.BOLDFACE_STYLE) != 0) { _currentRun.FontWeight = FontWeights.Bold; } if ((cdi.Style & ZStyles.EMPHASIS_STYLE) != 0) { _currentRun.FontStyle = FontStyles.Italic; } if ( (cdi.Style & ZStyles.REVERSE_STYLE) != 0) { _currentRun.Background = Brushes.Black; _currentRun.Foreground = Brushes.White; } if ( (cdi.Style & ZStyles.FIXED_WIDTH_STYLE) != 0) { _currentRun.FontFamily = new System.Windows.Media.FontFamily(Properties.Settings.Default.FixedWidthFont); } } if (_currentRun == null) { _currentRun = new Run(text); _p.Inlines.Add(_currentRun); } else { _currentRun.Text += text; if (_currentRun.Text.EndsWith(threeNewLines)) { StringBuilder sb = new StringBuilder(_currentRun.Text); while (sb.ToString().EndsWith(threeNewLines)) { sb.Remove(sb.Length - 2, 2); } _currentRun.Text = sb.ToString(); // } } _RTB.CaretPosition = _RTB.CaretPosition.DocumentEnd; })); }
private static Inline GetInline(FrameworkElement element, SubtitleDescription description) { FontFamily fontFamily = null; if (description.FontFace != null) fontFamily = new FontFamily(description.FontFace); Style style = null; Inline inline = null; switch (description.Type) { case InlineType.Run: var run = new Run(description.Text); if (description.FontSize != null) run.FontSize = double.Parse(description.FontSize); if (fontFamily != null) run.FontFamily = fontFamily; inline = run; break; case InlineType.LineBreak: var lineBreak = new LineBreak(); inline = lineBreak; break; case InlineType.Span: var span = new Span(); inline = span; break; case InlineType.Bold: var bold = new Bold(); inline = bold; break; case InlineType.Italic: var italic = new Italic(); inline = italic; break; case InlineType.Hyperlink: var hyperlink = new Hyperlink(); inline = hyperlink; break; case InlineType.Underline: var underline = new Underline(); inline = underline; break; } if (inline != null) { var span = inline as Span; if (span != null) { var childInlines = new List<Inline>(); foreach (var inlineDescription in description.Subtitles) { var childInline = GetInline(element, inlineDescription); if (childInline == null) continue; childInlines.Add(childInline); } span.Inlines.AddRange(childInlines); } } return inline; }
private void LinkRemove(Paragraph paragraph, Hyperlink hl) { Inline nextInline = hl.NextInline; Inline prevInline = hl.PreviousInline; int caretOffset = 0; int caretPosition = paragraph.ContentStart.GetOffsetToPosition(CaretPosition); if (CaretPosition.CompareTo(hl.ContentStart) > 0) caretOffset++; if (CaretPosition.CompareTo(hl.ContentEnd) > 0) caretOffset++; paragraph.Inlines.Remove(hl); foreach (var hlInline in hl.Inlines) { Inline newInline = null; if (hlInline is Run) { newInline = new Run(((Run)hlInline).Text); } else if (hlInline is LineBreak) { newInline = new LineBreak(); } if (newInline == null) continue; if (prevInline == null && nextInline == null) { paragraph.Inlines.Add(newInline); } else if (prevInline != null) { paragraph.Inlines.InsertAfter(prevInline, newInline); } else if (nextInline != null) { paragraph.Inlines.InsertBefore(nextInline, newInline); } prevInline = newInline; } if (caretPosition - caretOffset >= 0) { var newPosition = paragraph.ContentStart.GetPositionAtOffset(caretPosition - caretOffset); if (newPosition != null) CaretPosition = newPosition; else { CaretPosition = paragraph.ContentEnd; } } }
protected override void Append(LoggingEvent logging) { if (TextBox == null) { return; } if(logging.Level == Level.Debug && !IsDebugEnable) return; if(logging.Level == Level.Error && !IsErrorEnable) return; if(logging.Level == Level.Info && !IsInfoEnable) return; TextBox.Dispatcher.Invoke(() => { Paragraph p = TextBox.Document.Blocks.FirstBlock as Paragraph; if( p != null && p.Inlines.Count > 1024) p.Inlines.Remove(p.Inlines.FirstInline); TextPointer position = TextBox.CaretPosition.DocumentEnd; var lineBreak = new LineBreak(position); var text = new Run(mLayout.Format(logging), position); text.Foreground = COLORS[logging.Level]; TextBox.ScrollToEnd(); }); }
private void AddLineBreak() { _PriorLineBreaks++; // Create the LineBreak and buffer it LineBreak lineBreak = new LineBreak(); DocumentState state = _DocumentStates.Peek(); DecorateRun(lineBreak, state); _CurrentParagraph.Inlines.Add(lineBreak); }
IEnumerable<RawText> ExtractTextImpl(LineBreak br) { return new[] { new RawText() { Text = "\n", Start = br.ContentStart } }; }
public static void ParseLineBreak(MessagePack msgPack, LineBreak lineBreak) { ((TextElement)msgPack.CreateElement(MsgPackCat.ELEMTYPE_TEXT)).SetText("\r\n"); }
/// <summary> /// Renders DOM text elements recursively, i.e. including their childs. /// </summary> /// <param name="e">The root DOM text element.</param> /// <returns>The corresponding Wpf element.</returns> /// <exception cref="System.InvalidOperationException"> /// </exception> /// <exception cref="System.NotImplementedException"></exception> public object RenderRecursively(TextElement e) { object wpf = null; switch (e) { case BlockUIContainer buc: { wpf = new swd.BlockUIContainer(); } break; case FlowDocument flowDocument: { // make sure the standard colors were set flowDocument.Foreground = ExCSS.Color.Black; flowDocument.Background = ExCSS.Color.White; var flowDocumente = new swd.FlowDocument() { Name = NameOfFlowDocument }; if (TemplateBindingViewportWidth is null) { TemplateBindingViewportWidth = new Binding("ColumnWidth") { Source = flowDocumente } } ; if (TemplateBindingViewportHeight is null) { TemplateBindingViewportHeight = new Binding("ColumnWidth") { Source = flowDocumente } } ; // Binding to ColumnWidth is not optimal, but better than nothing! if (flowDocument.Background.HasValue) { flowDocumente.Background = GetBrushFromColor(flowDocument.Background.Value); } if (flowDocument.Foreground.HasValue) { flowDocumente.Foreground = GetBrushFromColor(flowDocument.Foreground.Value); } wpf = flowDocumente; } break; case Hyperlink hl: { var hle = new swd.Hyperlink(); if (!string.IsNullOrEmpty(hl.NavigateUri)) { if (System.Uri.TryCreate(hl.NavigateUri, UriKind.RelativeOrAbsolute, out var uri)) { hle.NavigateUri = uri; } } if (!string.IsNullOrEmpty(hl.TargetName)) { hle.TargetName = hl.TargetName; } wpf = hle; } break; case Image image: { var imagee = new System.Windows.Controls.Image(); if (!string.IsNullOrEmpty(image.Source)) { imagee.SetBinding(System.Windows.Controls.Image.SourceProperty, $"ImageProvider[{image.Source}]"); } if (image.Width == null && image.Height == null) { imagee.Stretch = System.Windows.Media.Stretch.Uniform; var binding = new Binding() { RelativeSource = RelativeSource.Self, Path = new System.Windows.PropertyPath("Source") }; binding.Converter = ImageToImageWidthConverter.Instance; imagee.SetBinding(System.Windows.Controls.Image.WidthProperty, binding); } else { imagee.Stretch = System.Windows.Media.Stretch.Uniform; } if (image.Width != null) { if (image.Width.IsPurelyAbsolute(out var widthPx)) { imagee.Width = widthPx; } else { var multibinding = new MultiBinding(); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportHeight.Source, Path = TemplateBindingViewportHeight.Path }); multibinding.Converter = CompoundLengthConverter.Instance; multibinding.ConverterParameter = GetCompoundLengthConverterParameters(image.Width); imagee.SetBinding(System.Windows.Controls.Image.WidthProperty, multibinding); } } if (image.Height != null) { if (image.Height.IsPurelyAbsolute(out var heightPx)) { imagee.Height = heightPx; } else { var multibinding = new MultiBinding(); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportHeight.Source, Path = TemplateBindingViewportHeight.Path }); multibinding.Converter = CompoundLengthConverter.Instance; multibinding.ConverterParameter = GetCompoundLengthConverterParameters(image.Height); imagee.SetBinding(System.Windows.Controls.Image.HeightProperty, multibinding); } } // set max-width and max-height if (image.MaxWidth != null && image.MaxWidth.Value.IsAbsolute) { imagee.MaxWidth = image.MaxWidth.Value.ToPixel(); } else if (image.MaxWidth == null || image.MaxWidth.Value.Type == ExCSS.Length.Unit.Vw) { double vwValue = image.MaxWidth.HasValue ? image.MaxWidth.Value.Value : 100; var binding = new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }; binding.Converter = RelativeSizeConverter.Instance; binding.ConverterParameter = vwValue; imagee.SetBinding(System.Windows.Controls.Image.MaxWidthProperty, binding); } else { throw new InvalidProgramException(); } if (image.MaxHeight != null && image.MaxHeight.Value.IsAbsolute) { imagee.MaxHeight = image.MaxHeight.Value.ToPixel(); } else if (image.MaxHeight == null || image.MaxHeight.Value.Type == ExCSS.Length.Unit.Vh) { double vhValue = image.MaxHeight.HasValue ? image.MaxHeight.Value.Value : 100; var binding = new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }; binding.Converter = RelativeSizeConverter.Instance; binding.ConverterParameter = vhValue; imagee.SetBinding(System.Windows.Controls.Image.MaxHeightProperty, binding); } else { throw new InvalidProgramException(); } wpf = imagee; } break; case InlineUIContainer iuc: { var inlineuiContainere = new swd.InlineUIContainer(); wpf = inlineuiContainere; } break; case LineBreak lb: { wpf = new swd.LineBreak(); } break; case List list: { var liste = new swd.List(); if (list.MarkerStyle.HasValue) { liste.MarkerStyle = ToMarkerStyle(list.MarkerStyle.Value); } wpf = liste; } break; case ListItem li: { wpf = new swd.ListItem(); } break; case Paragraph p: { var pe = new swd.Paragraph(); if (p.TextDecorations.HasValue) { pe.TextDecorations = ToTextDecorations(p.TextDecorations.Value); } if (p.TextIndent.HasValue) { pe.TextIndent = p.TextIndent.Value.IsAbsolute ? p.TextIndent.Value.ToPixel() : 0; } wpf = pe; } break; case Run run: { if (SplitIntoWords) { wpf = CreateTextElement_SeparateWords(run.Text); } else if (SplitIntoSentences) { wpf = CreateTextElement_SeparateSentences(run.Text); } else { wpf = new swd.Run(run.Text); } } break; case Section s: { wpf = new swd.Section(); } break; case Span span: { wpf = new swd.Span(); } break; case Table tb: { var tbe = new swd.Table(); foreach (var c in tb.Columns) { if (c.Width.HasValue) { tbe.Columns.Add(new swd.TableColumn() { Width = new System.Windows.GridLength(c.Width.Value) }); } else { tbe.Columns.Add(new swd.TableColumn()); } } wpf = tbe; } break; case TableCell tc: { var tce = new swd.TableCell(); if (1 != tc.ColumnSpan) { tce.ColumnSpan = tc.ColumnSpan; } if (1 != tc.RowSpan) { tce.RowSpan = tc.RowSpan; } if (tc.BorderBrush.HasValue) { tce.BorderBrush = new System.Windows.Media.SolidColorBrush(ToColor(tc.BorderBrush.Value)); } if (tc.BorderThickness.HasValue) { tce.BorderThickness = ToThickness(tc.BorderThickness.Value); } wpf = tce; } break; case TableRow trow: { wpf = new swd.TableRow(); } break; case TableRowGroup trg: { wpf = new swd.TableRowGroup(); } break; default: { wpf = null; } break; } // Render TextElement properties if (wpf is swd.TextElement te) { if (!string.IsNullOrEmpty(e.FontFamily)) { te.FontFamily = GetFontFamily(e.FontFamily); } if (e.FontSize.HasValue) { var fs = e.FontSize.Value; fs = Math.Max(0.004, fs); te.FontSize = fs; } if (e.FontStyle.HasValue) { te.FontStyle = ToFontStyle(e.FontStyle.Value); } if (e.FontWeight.HasValue) { te.FontWeight = ToFontWeight(e.FontWeight.Value); } if (e.Foreground.HasValue && e.Foreground != e.ForegroundInheritedOnly) { te.Foreground = GetBrushFromColor(e.Foreground.Value); } if (e.Background.HasValue && e.Background != e.BackgroundInheritedOnly) { te.Background = GetBrushFromColor(e.Background.Value); } } // now special properties if (e is Block b && wpf is swd.Block be) { if (b.Margin.HasValue) { be.Margin = ToThickness(b.Margin.Value); } if (b.Padding.HasValue) { be.Padding = ToThickness(b.Padding.Value); } if (b.BorderBrush.HasValue) { be.BorderBrush = new System.Windows.Media.SolidColorBrush(ToColor(b.BorderBrush.Value)); } if (b.BorderThickness.HasValue) { be.BorderThickness = ToThickness(b.BorderThickness.Value); } if (b.TextAlignment.HasValue) { be.TextAlignment = ToTextAlignment(b.TextAlignment.Value); } if (b.LineHeight.HasValue) { be.LineHeight = b.LineHeight.Value; } } if (e is Inline i && wpf is swd.Inline ie) { if (i.VerticalAlignment.HasValue) { ie.BaselineAlignment = ToBaselineAlignment(i.VerticalAlignment.Value); } } // finished rendering the attributes // now, render all children foreach (var child in e.Childs) { var childe = RenderRecursively(child); switch (wpf) { case swd.Figure figure: figure.Blocks.Add((swd.Block)childe); break; case swd.Floater floater: floater.Blocks.Add((swd.Block)childe); break; case swd.FlowDocument flowDocument: flowDocument.Blocks.Add((swd.Block)childe); break; case swd.List list: list.ListItems.Add((swd.ListItem)childe); break; case swd.ListItem listItem: listItem.Blocks.Add((swd.Block)childe); break; case swd.Section section: section.Blocks.Add((swd.Block)childe); break; case swd.Table table: table.RowGroups.Add((swd.TableRowGroup)childe); break; case swd.TableCell tableCell: tableCell.Blocks.Add((swd.Block)childe); break; case swd.TableRow tableRow: tableRow.Cells.Add((swd.TableCell)childe); break; case swd.TableRowGroup tableRowGroup: tableRowGroup.Rows.Add((swd.TableRow)childe); break; // now elements that can contain inlines case swd.Paragraph paragraph: paragraph.Inlines.Add((swd.Inline)childe); break; case swd.Span span: span.Inlines.Add((swd.Inline)childe); break; // now some specialties case swd.InlineUIContainer inlineUIContainer: if (inlineUIContainer.Child != null) { throw new InvalidOperationException($"{nameof(swd.InlineUIContainer)} can not contain more than one child"); } inlineUIContainer.Child = (System.Windows.UIElement)childe; break; case swd.BlockUIContainer blockUIContainer: if (blockUIContainer.Child != null) { throw new InvalidOperationException($"{nameof(swd.BlockUIContainer)} can not contain more than one child"); } blockUIContainer.Child = (System.Windows.UIElement)childe; break; default: throw new NotImplementedException(); } } if (AttachDomAsTags) { if (wpf is System.Windows.FrameworkContentElement conEle) { conEle.Tag = e; } else if (wpf is System.Windows.FrameworkElement uiEle) { uiEle.Tag = e; } } return(wpf); }
private static TextPointer GetPointerFromCharOffset(LineBreak lineBreak, ref int charOffset) { return lineBreak.ElementEnd; }
private static int GetCharOffsetToPosition(LineBreak lineBreak, TextPointer position, out TextPointer result) { result = lineBreak.ElementEnd; return 0; }
private Inline Clone(Inline inline) { Inline newInline = null; if (inline is InlineTableCellIndexValue) { var inlineValue = (InlineTableCellIndexValue)inline; newInline = new InlineTableCellIndexValue() { AggregateGroup = inlineValue.AggregateGroup, Index = inlineValue.Index, Format = inlineValue.Format, Value = inlineValue.Value, }; } else if (inline is InlineTableCellValue) { var inlineValue = (InlineTableCellValue)inline; newInline = new InlineTableCellValue() { AggregateGroup = inlineValue.AggregateGroup, PropertyName = inlineValue.PropertyName, Format = inlineValue.Format, Value = inlineValue.Value, }; } else if (inline is InlineAggregateValue) { var inlineValue = (InlineAggregateValue)inline; newInline = new InlineAggregateValue() { AggregateGroup = inlineValue.AggregateGroup, EmptyValue = inlineValue.EmptyValue, ErrorValue = inlineValue.ErrorValue, Format = inlineValue.Format, Value = inlineValue.Value, }; } else if (inline is InlineContextValue) { var inlineValue = (InlineContextValue)inline; newInline = new InlineContextValue() { AggregateGroup = inlineValue.AggregateGroup, Type = inlineValue.Type, Format = inlineValue.Format, Value = inlineValue.Value, }; } else if (inline is InlineDocumentValue) { var inlineValue = (InlineDocumentValue)inline; newInline = new InlineDocumentValue() { AggregateGroup = inlineValue.AggregateGroup, PropertyName = inlineValue.PropertyName, Format = inlineValue.Format, Value = inlineValue.Value, }; } else if (inline is Run) { var run = (Run)inline; newInline = new Run() { Text = run.Text, }; } else if (inline is LineBreak) newInline = new LineBreak(); else if (inline is Bold) { var bold = new Bold(); foreach (var inl in ((Bold)inline).Inlines) bold.Inlines.Add(Clone(inl)); newInline = bold; } if (newInline != null) { CopyProperties(inline, newInline); return newInline; } throw new NotSupportedException(); }
private UIElement GetLogControl(List<WorkReportLogEntity> logs, int rowIndex, int columnCount, int logCount, GridLength length) { int margin = 2; string groupName = Guid.NewGuid().ToString(); var userLogControl = new LogGrid { Header = "LOG质量" }; var gridLog = new Grid { ShowGridLines = false, Background = GetColor(5) }; var logGroup = logs; if (logGroup.Count > 0) { for (int i1 = 0; i1 < columnCount + margin; i1++) { if (i1==0) { gridLog.ColumnDefinitions.Add(new ColumnDefinition { Width =new GridLength(115), }); } else { gridLog.ColumnDefinitions.Add(new ColumnDefinition { Width =new GridLength(100), }); } Rectangle rec = CreateVertLine(i1, logGroup.Count + 1); gridLog.Children.Add(rec); } for (int i1 = 0; i1 < logGroup.Count + 1; i1++) { gridLog.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto, MinHeight = 40 }); Rectangle rectSub = CreateHorLine(i1, columnCount + margin); if (i1 == logGroup.Count() && rowIndex != logCount * 2) { rectSub.Height = 2; rectSub.Fill = new SolidColorBrush(Colors.Black); rectSub.Margin = new Thickness(0, 1, 0, -1); } gridLog.Children.Add(rectSub); } Rectangle rectlogo = CreateRectangler(2); rectlogo.Margin = new Thickness(1); Grid.SetColumn(rectlogo, 0); Grid.SetColumnSpan(rectlogo,2); Grid.SetRow(rectlogo, 0); gridLog.Children.Add(rectlogo); var lableLogName = new Border { Child = new TextBlock { Text = "LOG名称", FontSize = 12, FontWeight = FontWeights.Bold, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(20, 0, 0, 0) }, Margin = new Thickness(1, 0, 1, 1) }; lableLogName.SetValue(Canvas.ZIndexProperty, 10); Grid.SetColumn(lableLogName, 0); Grid.SetRow(lableLogName, 0); lableLogName.HorizontalAlignment = HorizontalAlignment.Stretch; lableLogName.VerticalAlignment = VerticalAlignment.Stretch; gridLog.Children.Add(lableLogName); var lableLogQuality = new Border { Child = new TextBlock { Text = "Log质量", FontSize = 12, FontWeight = FontWeights.Bold, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(20, 0, 0, 0) }, Margin = new Thickness(1, 0, 1, 1) }; lableLogName.SetValue(Canvas.ZIndexProperty, 10); Grid.SetColumn(lableLogQuality, 1); Grid.SetRow(lableLogQuality, 0); lableLogName.HorizontalAlignment = HorizontalAlignment.Stretch; lableLogName.VerticalAlignment = VerticalAlignment.Stretch; gridLog.Children.Add(lableLogQuality); for (int m = 0; m < columnCount; m++) { var kpi = logs[0].Kpis[m]; var lableLog = new TextBlock { Text = kpi.KpiName + (kpi.KpiName.Contains("FTP") ? "" : "(%)"), FontSize = 12, FontWeight = FontWeights.Bold, MaxWidth = 80, TextWrapping = TextWrapping.Wrap }; lableLog.SetValue(ToolTipService.ToolTipProperty, kpi.KpiName + (kpi.KpiName.Contains("FTP") ? "" : "(%)")); Grid.SetColumn(lableLog, m + margin); lableLog.VerticalAlignment = VerticalAlignment.Center; lableLog.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(lableLog, 0); lableLog.SetValue(Canvas.ZIndexProperty, 10); gridLog.Children.Add(lableLog); } var countLog = 0; for (int i = 0; i < logGroup.Count(); i++) { countLog++; StackPanel stackPanelLog = new StackPanel() {Orientation = Orientation.Horizontal}; var rb = new RadioButton() { Tag = logGroup[i], VerticalAlignment = VerticalAlignment.Center, GroupName = groupName+logGroup[i].LogServertype }; rb.SetBinding(RadioButton.IsCheckedProperty, new Binding() { Source = rb.Tag, Path = new PropertyPath("IsSelected"), Mode = BindingMode.TwoWay }); stackPanelLog.Children.Add(rb); var logtxt = new TextBlock { FontSize = 12, FontWeight = FontWeights.Bold, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(20, 0, 0, 0) }; var run = new Run { Text = logGroup[i].LogName, }; logtxt.Inlines.Add(run); var br = new LineBreak(); logtxt.Inlines.Add(br); var dataType = new Underline(); dataType.Inlines.Add(new Run { Text = logGroup[i].LogServertype + "(打点图)" }); logtxt.Inlines.Add(dataType); stackPanelLog.Children.Add(logtxt); var lableNameLog1 = new Border { Child = stackPanelLog, Margin = new Thickness(1, 0, 1, 1), Cursor = Cursors.Hand }; lableNameLog1.MouseLeftButtonDown += (s, e) => { }; lableNameLog1.SetValue(Canvas.ZIndexProperty, 10); Grid.SetColumn(lableNameLog1, 0); Grid.SetRow(lableNameLog1, countLog); lableNameLog1.VerticalAlignment = VerticalAlignment.Stretch; lableNameLog1.HorizontalAlignment = HorizontalAlignment.Stretch; gridLog.Children.Add(lableNameLog1); Rectangle rectbg = CreateGridRowBackground(1, countLog); gridLog.Children.Add(rectbg); TextBlock logQuality = new TextBlock() { Foreground = GetColor(logGroup[i].Result), FontFamily = new FontFamily("Microsoft YaHei"), FontSize = 14, FontWeight = FontWeights.Bold, }; logQuality.Text = GetResult(logGroup[i].Result); Grid.SetColumn(logQuality, 1); Grid.SetRow(logQuality, countLog); logQuality.VerticalAlignment = VerticalAlignment.Center; logQuality.HorizontalAlignment = HorizontalAlignment.Center; gridLog.Children.Add(logQuality); if (logs[i].Kpis==null) { continue; } for (int m = 0; m < columnCount; m++) { var kpi = logs[i].Kpis[m]; Rectangle newrect = CreateRectangler(1); newrect.Margin = new Thickness(1, 1, 1, 1); Grid.SetColumn(newrect, m + margin); Grid.SetRow(newrect, 0); gridLog.Children.Add(newrect); var borderlog = new TextBlock { Text = kpi.KpiName.Contains("FTP") ? kpi.KpiValue.ToString() : (kpi.KpiValue.Value * 100).ToString("00.0"), Foreground =GetColor(logs[i].Result), FontFamily = new FontFamily("Microsoft YaHei"), FontSize = 12, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; borderlog.SetValue(ToolTipService.ToolTipProperty, kpi.KpiRange); borderlog.SetValue(Canvas.ZIndexProperty, 100); Grid.SetColumn(borderlog, m + margin); Grid.SetRow(borderlog, countLog); gridLog.Children.Add(borderlog); } } } userLogControl.Content = new Border() { Child = gridLog,BorderBrush = new SolidColorBrush(Colors.Black),BorderThickness = new Thickness(1)}; ; return userLogControl; }
private void ParseLineBreak(MessagePack msgPack, LineBreak lineBreak) { ((InstanceAnswerPro.Core.TextElement)msgPack.CreateElement(MsgPackCat.ELEMTYPE_TEXT)).SetText("\r\n"); }
private Inline CloneInline(Inline inline) { Inline retVal = null; if (inline is LineBreak) retVal = new LineBreak(); else if (inline is Span) retVal = new Span(); else if (inline is Run) { retVal = new Run(((Run) inline).Text); } if (inline.ReadLocalValue(Inline.BackgroundProperty) != DependencyProperty.UnsetValue) retVal.Background = inline.Background; if (inline.ReadLocalValue(Inline.ForegroundProperty) != DependencyProperty.UnsetValue) retVal.Foreground = inline.Foreground; if (inline.ReadLocalValue(Inline.FontFamilyProperty) != DependencyProperty.UnsetValue) retVal.FontFamily = inline.FontFamily; if (inline.ReadLocalValue(Inline.FontSizeProperty) != DependencyProperty.UnsetValue) retVal.FontSize = inline.FontSize; if (inline.ReadLocalValue(Inline.FontStretchProperty) != DependencyProperty.UnsetValue) retVal.FontStretch = inline.FontStretch; if (inline.ReadLocalValue(Inline.FontStyleProperty) != DependencyProperty.UnsetValue) retVal.FontStyle = inline.FontStyle; if (inline.ReadLocalValue(Inline.FontWeightProperty) != DependencyProperty.UnsetValue) retVal.FontWeight = inline.FontWeight; if (inline.ReadLocalValue(Inline.TextEffectsProperty) != DependencyProperty.UnsetValue) retVal.TextEffects = inline.TextEffects; if (inline.ReadLocalValue(Inline.TextDecorationsProperty) != DependencyProperty.UnsetValue) retVal.TextDecorations = inline.TextDecorations; return retVal; }
private static Inline GetInline(FrameworkElement element, InlineDescription description) { Style style = null; if (!string.IsNullOrEmpty(description.StyleName)) { style = element.FindResource(description.StyleName) as Style; if (style == null) throw new InvalidOperationException("The style '" + description.StyleName + "' cannot be found"); } Inline inline = null; switch (description.Type) { case InlineType.Run: var run = new Run(description.Text); inline = run; break; case InlineType.LineBreak: var lineBreak = new LineBreak(); inline = lineBreak; break; case InlineType.Span: var span = new Span(); inline = span; break; case InlineType.Bold: var bold = new Bold(); inline = bold; break; case InlineType.Italic: var italic = new Italic(); inline = italic; break; case InlineType.Hyperlink: var hyperlink = new Hyperlink(); inline = hyperlink; break; case InlineType.Underline: var underline = new Underline(); inline = underline; break; } if (inline != null) { var span = inline as Span; if (span != null) { var childInlines = description.Inlines.Select(inlineDescription => GetInline(element, inlineDescription)) .Where(childInline => childInline != null) .ToList(); span.Inlines.AddRange(childInlines); } if (style != null) inline.Style = style; } return inline; }
/// <summary> /// Insert a LineBreak element at the given position. /// If position's parent is a Paragraph or Span, simply insert a LineBreak element at this position. /// Otherwise, ensure insertion position and insert a LineBreak element at insertion position in text content. /// </summary> /// <param name="position"> /// </param> /// <returns> /// TextPointer positioned in the beginning of a Run immediately following a LineBreak inserted. /// </returns> internal static TextPointer InsertLineBreak(TextPointer position) { if (!TextSchema.IsValidChild(/*position*/position, /*childType*/typeof(LineBreak))) { // Ensure insertion position, in case position's parent is not a paragraph/span element. position = TextRangeEditTables.EnsureInsertionPosition(position); } if (TextSchema.IsInTextContent(position)) { // Split parent Run element, if position is inside of Run scope. position = SplitElement(position); } Invariant.Assert(TextSchema.IsValidChild(/*position*/position, /*childType*/typeof(LineBreak)), "position must be in valid scope now to insert a LineBreak element"); LineBreak lineBreak = new LineBreak(); position.InsertTextElement(lineBreak); return lineBreak.ElementEnd.GetInsertionPosition(LogicalDirection.Forward); }
private void AppendLineBreak(HtmlNode node, Paragraph paragraph, Span span, bool traverse) { LineBreak lineBreak = new LineBreak(); if (span != null && !(span is Hyperlink)) //bug fix from trello: [Bug]: App crashes when the post "Metro navnet er fortid" { span.Inlines.Add(lineBreak); } else if (paragraph != null) { paragraph.Inlines.Add(lineBreak); } if (traverse) AppendChildren(node, paragraph, span); }
private void AppendLineBreak(HtmlNode node, Paragraph paragraph, Span span, bool traverse) { LineBreak lineBreak = new LineBreak(); if (span != null) { span.Inlines.Add(lineBreak); } else if (paragraph != null) { paragraph.Inlines.Add(lineBreak); } if (traverse) AppendChildren(node, paragraph, span); }