我有一个包含一些自定义 Span
的 RichTextBlock
。我想在触发 Right-Tapped
事件时更改该范围的 Background
颜色。我可以访问那个 span
但它没有 Background
属性。
我该怎么做?
最佳答案
RichTextBlock
和Span
中没有Background
属性,我们不能将Background
设置为跨度
。
如果您希望 Span 具有“背景”,您应该能够在 InlineUIContainer
中添加 Grid
或 StackPanel
.
例如:
<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>
还有RichTextBlock
用来显示数据,如果你想编辑文本,你应该可以使用RichEditBox
.
然后我们应该能够使用ITextRange.CharacterFormat.BackgroundColor
来改变文本的背景。 stackoverflow中也有类似案例,请引用。
关于c# - 如何更改自定义跨度的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41074614/