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.
You can iterate over the Inlines
property of the Span
:
int count = 0;
foreach(Inline inline in span.Inlines)
{
if (inline is Bold) count++;
}