private static void OnInlinesChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { if (obj is TextBlock textBlock) { textBlock.Inlines.Clear(); if (e.NewValue is IEnumerable <InlineModel> inlines) { ICollectionExtensions.AddRange(textBlock.Inlines, inlines.Select(i => i.Create(textBlock))); } } else if (obj is Paragraph paragraph) { paragraph.Inlines.Clear(); if (e.NewValue is IEnumerable <InlineModel> inlines && RecursiveEnumerable.While(paragraph.Parent, obj => obj is FrameworkContentElement fce, obj => ((FrameworkContentElement)obj).Parent).LastOrDefault() is FrameworkElement fe) { ICollectionExtensions.AddRange(paragraph.Inlines, inlines.Select(i => i.Create(fe))); } } }
public new T Create <T>(T span, FrameworkElement coveringElement) where T : Span { ICollectionExtensions.AddRange(span.Inlines, Inlines.Select(i => i.Create(coveringElement))); return(base.Create(span, coveringElement)); }