/// <summary> /// Gets a <see cref="RichTextBlock"/> from given <see cref="UIElementCollection"/> or creates and adds one. /// </summary> /// <param name="elements">The <see cref="UIElementCollection"/> collection to add <see cref="RichTextBlock"/> to.</param> /// <returns>The last <see cref="RichTextBlock"/> of the collection.</returns> protected RichTextBlock GetOrCreateLastRichTextBlock(UIElementCollection elements) { if (elements.LastOrDefault() is RichTextBlock textBlock) { return(textBlock); } textBlock = new RichTextBlock(); elements.Add(textBlock); return(textBlock); }
/// <summary> /// Loops through children of an <see cref="INode"/> and appends as <see cref="UIElement"/> to given <see cref="UIElementCollection"/>. /// </summary> /// <param name="node">The parent <see cref="INode"/>.</param> /// <param name="elements">The <see cref="UIElementCollection"/> collection to add elements to.</param> protected void AddChildren(INode node, UIElementCollection elements) { foreach (var child in node.ChildNodes) { var element = GenerateUIElementForNode(child, elements); if (elements.LastOrDefault() != element) { elements.Add(element); } } }