c# - 如何更改自定义跨度的背景颜色?

标签 c# uwp richtextblock

我有一个包含一些自定义 SpanRichTextBlock。我想在触发 Right-Tapped 事件时更改该范围的 Background 颜色。我可以访问那个 span 但它没有 Background 属性。

我该怎么做?

最佳答案

RichTextBlockSpan 中没有Background 属性,我们不能将Background 设置为跨度

如果您希望 Span 具有“背景”,您应该能够在 InlineUIContainer 中添加 GridStackPanel .

例如:

<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/

相关文章:

c# - 如何计算 UWP BackgroundDownloader 中的下载速度?

ios - UWP/WinRT 相当于 NSDataDetector

c# - 将按钮插入富文本 block

c# - 为 WPF 文本框实现验证

c# - ASP.NET Core - 如何在另一个 Controller 中重用在一个 Controller 中创建的方法?

c# - 设计器 resx 文件仍然为空

c++ - UWP ListView 占用的高度超过可用高度

c# - 在 metro 应用程序的 RichTextBlock 中加载 HTMl

c# - 在 Canvas 上拖放形状