4

Is it possible to apply a background color to the inline text of a TextBlock instead of the entire rectangular bounds of the TextBlock? In other words, I would like to have this:

Screenshot

<TextBlock TextWrapping="Wrap">
    <!-- No such "Background" property -->
    <Span Background="Red">
        The quick brown fox jumps over the lazy dog
    </Span>
</TextBlock>

(Just like <span style="background-color: red"> in HTML)

Instead of this:

Screenshot

<Border Background="Red">
    <TextBlock TextWrapping="Wrap">
        The quick brown fox jumps over the lazy dog
    </TextBlock>
</Border>

Is this even supported? I've been looking through the documentation for the TextBlock and RichTextBlock classes but I can't see any way of setting the background of the inline text. I think WPF supports this.


EDIT

I should mention, I need this to work with automatically wrapped text. I don't know how many lines there will be, or else I could just manually use a Border for each line of text.

1 Answer 1

3

It seems that this is not currently supported in UWP apps.

WPF has a Background property for Run elements, which can be used inside TextBlock, but UWP's Run does not support this.

The only way I can think of to implement this would be using HTML and a WebView, or somehow using Win2D rendering, both of which are quite cumbersome solutions...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.