/// <summary> /// Erweitert die Ursprüngliche methode dahingehend, dass der Paragraph nur hinzugefügt wird, wenn er nicht leer ist /// </summary> /// <param name="col"></param> /// <param name="reference"></param> /// <param name="newParapgraph"></param> /// <param name="removeEmpty"></param> public static void InsertBefore(this BlockCollection col, Paragraph reference, Paragraph newParapgraph, bool removeEmpty) { if (newParapgraph.IsEmpty() && removeEmpty) { return; } col.InsertBefore(reference, newParapgraph); }
private void ChatWriteStrings(string[] mStr) { Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(new Bold(new Run(DateTime.Now.ToString() + "\r\n"))); foreach (string item in mStr) { paragraph.Inlines.Add(new Run(item + "\r\n")); } BlockCollection Blocks = lbChat.Document.Blocks; if (Blocks.Count == 0) { Blocks.Add(paragraph); } else { Blocks.InsertBefore(Blocks.FirstBlock, paragraph); } }
public void InsertSections(BlockCollection blocks, int hdDepth) { var cur = blocks.FirstBlock; while (cur != null) { if (GetHeadingDepth(cur) >= hdDepth) { var sec = new Section(); sec.BorderThickness = new Thickness(2); sec.BorderBrush = new SolidColorBrush(Colors.Gray); sec.Margin = new Thickness(5); blocks.InsertBefore(cur, sec); blocks.Remove(cur); sec.Blocks.Add(cur); cur = sec.NextBlock; while (cur != null) { int depth = GetHeadingDepth(cur); if (0<depth && depth <= hdDepth) break; var next = cur.NextBlock; blocks.Remove(cur); sec.Blocks.Add(cur); cur = next; } InsertSections(sec.Blocks, hdDepth + 1); } else { cur = cur.NextBlock; } } }