Search code examples
c#wpftextblock

Get the value of a span in a Textblock


After converting a SVG to XAML I got a lot of textblocks looking like this :

<TextBlock xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontSize="10"  Foreground="#FF000000"Name="text324947"><Span  FontSize="10">79</Span></TextBlock>

Now the question is : how can I access the Text inside the span ? The Text Property of my TextBlock is Empty.

Thanks


Solution

  • Use the Inlines property (see link).

    Given your XAML, you may do this:

    TextBlock tb = this.txt
    Span span = (Span) tb.Inlines.FirstInline;
    Run run = (Run) span.Inlines.FirstInline;
    string text = run.Text;