views:

14

answers:

2

How do I make a disabled RichTextbox with a transparent background?

I'd like to use the RichTextBox to display some rich text but make it disabled, so the text can't be edited. I want the background to be transparent while it's disabled, but the default behavior is to make the background greyed when the control is disabled. I've experimented with overriding the ControlTemplate and Styles but no luck.

UPDATE: Setting the background to transparent works great as long as I don't set IsEnabled="False". There is a style trigger in the base ControlTemplate that resets the background when the control is disabled, but I can't figure out how to override it.

+1  A: 

Hi,

you can just set the Background property of the RichTextBox transparent. HTH.

<Grid>
    <Image Source="Resources/nelson.png" />
    <RichTextBox Background="Transparent" IsReadOnly="True">
        <FlowDocument>
            <Paragraph>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et 
                dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, 
                no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy 
                eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et 
                ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur 
                sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et 
                accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</Paragraph>
        </FlowDocument>
    </RichTextBox>
</Grid>

alt text

andyp
This doesn't work, because as soon as I set IsEnabled=false the background is greyed out. This is set in the ControlTemplate for the RichTextBox control, but I can't figure out how to override it.
Dave Swersky
Not if you use IsReadOnly=true instead of IsEnabled=false.
andyp
+1  A: 
<RichTextBox Background="Transparent" IsReadOnly="True">

Works as well as

this.richTextBox1.IsReadOnly = "true";

You do not need to use the IsEnabled property, as the IsReadOnly does not allow the user to interact, which is what you where looking for right?

Pieces
+100 if I could, as usual I'm trying to make this harder than it really is! :)
Dave Swersky
I know how that is man haha.
Pieces