2

I have a RichTextBlock that contains some custom Span. I want when Right-Tapped event fired I change the Background color of that span. I can access to that span but It doesn't have Background property.

how can I do it?

Maryam
  • 883
  • 10
  • 24

1 Answers1

0

There is no Background property in RichTextBlock and Span that we can not set the Background to the Span.

If you want the Span has "background", you should be able to add Grid or StackPanel in the InlineUIContainer.

For example:

<RichTextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
    <Paragraph>
        <InlineUIContainer>
            <Grid Background="Blue">
                <RichTextBlock>
                    <Paragraph>
                        <Span>This is
                            <Bold>mixed content</Bold> with multiple text areas
                            <Italic>and inlines</Italic> .
                        </Span>
                    </Paragraph>
                </RichTextBlock>
            </Grid>
        </InlineUIContainer>
    </Paragraph>
    <Paragraph>
        <Span>This is
            <Bold>mixed content</Bold> with multiple text areas
            <Italic>and inlines</Italic> .
        </Span>
    </Paragraph>
</RichTextBlock>

Also the RichTextBlock is used to show the data, if you want to edit the text, you should be able to use RichEditBox.

Then we should be able to use ITextRange.CharacterFormat.BackgroundColor to change the background of the Text. There is a similar case in stackoverflow, please refer it.

Community
  • 1
  • 1
Jayden
  • 3,276
  • 1
  • 10
  • 14