Finding all Images in a FlowDocument

后端 未结 4 1804
花落未央
花落未央 2020-12-19 17:34

Since I am pretty new to WPF FlowDocuments I would like to ask if the code below is correct. It is supposed to return all Images contained in a FlowDocument as List:

4条回答
  •  难免孤独
    2020-12-19 18:16

    
    static IEnumerable GetElementsOfType(DependencyObject parent) where T : class
    {
       var childElements = LogicalTreeHelper.GetChildren(parent).OfType().ToList();
       return childElements.SelectMany(GetElementsOfType).Union(childElements.OfType());
    }
    ....
    var images = GetElementsOfType(document)
    

提交回复
热议问题