RichTextBox 滚动条图像作为背景 c# wpf

RichTextBox scrollbar image as background c# wpf

我想在我的 richtextbox 命令中使用图像作为背景。 我正在使用,但我只能将背景值设置为已经定义的颜色,而不是图像。 (我使用的是 scrollbarviewer 但它没有显示在我的 richtextbox 中)

<RichTextBox x:Name="richTextBox" HorizontalAlignment="Left" Height="285" VerticalAlignment="Top" Width="880" VerticalScrollBarVisibility="Visible" IsReadOnly="True" Foreground="#FFA02626" Background="{x:Null}">
            <RichTextBox.Resources>
                <Style TargetType="ScrollBar">
                    <Setter Property="Background" Value="Red"/>
                </Style>
            </RichTextBox.Resources>
</RichTextBox>

这样试试-

<RichTextBox>
    <RichTextBox.Background>
        <ImageBrush ImageSource="some.jpg"/>
    </RichTextBox.Background>
</RichTextBox>

看看这是否有帮助。

Value可以是任何对象,所以可以是ImageBrush。您可以使用元素语法来完成。

<RichTextBox x:Name="richTextBox" HorizontalAlignment="Left" Height="285" VerticalAlignment="Top" Width="880" VerticalScrollBarVisibility="Visible" IsReadOnly="True" Foreground="#FFA02626" Background="{x:Null}">
    <RichTextBox.Resources>
        <Style TargetType="ScrollBar">
            <Setter Property="Background">
                <Setter.Value>
                <ImageBrush ImageSource="cool-northern-lights-pic-4.jpg"/>
                </Setter.Value>
            </Setter>
        </Style>
    </RichTextBox.Resources>
</RichTextBox>