// <copyright file="FlowDocumentHelper.cs" company="GoalBook"> // Copyright © 2009 Mark Brownsword. All rights reserved. // This source code and supporting files are licensed under The Code Project // Open License (CPOL) as detailed at http://www.codeproject.com/info/cpol10.aspx. // </copyright> namespace GoalBook.Infrastructure.Helpers { #region Using Statements using System.Collections.Generic; using System.Windows.Documents; #endregion /// <summary> /// FlowDocument Helper. /// </summary> public class FlowDocumentHelper { #region Constants and Enums #endregion #region Instance and Shared Fields /// <summary> /// Declaration for flowDocument. /// </summary> private FlowDocument flowDocument; #endregion #region Constructors /// <summary> /// Initializes a new instance of the FlowDocumentHelper class. /// </summary> /// <param name="flowDocument">FlowDocument parameter</param> public FlowDocumentHelper(FlowDocument flowDocument) { this.flowDocument = flowDocument; } #endregion #region Delegates and Events #endregion #region Properties #endregion #region Public and internal Methods /// <summary> /// Get Hyperlinks. /// </summary> /// <returns>Hyperlink enumerable list</returns> public IEnumerable<Hyperlink> GetHyperlinks() { return this.LocateHyperlinks(this.flowDocument.Blocks); } #endregion #region Base Class Overrides #endregion #region Private and Protected Methods /// <summary> /// Locate Hyperlinks. /// </summary> /// <param name="blockCollection">BlockCollection parameter</param> /// <returns>Hyperlink enumerable list</returns> private IEnumerable<Hyperlink> LocateHyperlinks(BlockCollection blockCollection) { foreach (Block block in blockCollection) { if (block is Paragraph) { foreach (Inline inline in (block as Paragraph).Inlines) { if (inline is Hyperlink) { yield return inline as Hyperlink; } } } else if (block is List) { foreach (ListItem listItem in (block as List).ListItems) { // Recurse Blocks in each ListItem. foreach (Hyperlink hyperlink in this.LocateHyperlinks(listItem.Blocks)) { yield return hyperlink; } } } } } #endregion #region Event Handlers #endregion } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)