1

I have WPF Span that is used as a source to a TextBlock. I am doing some tests and it would be very helpful to know in code how many of which type of component is inside of the Span.

For example, at one point I insert a new Bold() into the span's inlines. How would I check that there is exactly one Bold component contained inside of the span?

I'm not too sure how to search Span.Inlines to retrieve this number.

bluebit
  • 2,987
  • 7
  • 34
  • 42

1 Answers1

1

You can iterate over the Inlines property of the Span :

int count = 0;
foreach(Inline inline in span.Inlines)
{
    if (inline is Bold) count++;
}
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758