TextBlock Background Stretch removal property

I have a TextBox defined like this:

<TextBox>
    <TextBox.Background>
        <VisualBrush>
            <VisualBrush.Visual>
                <StackPanel>
                    <TextBlock Background="Blue" Opacity="0.5" Text="155"/>
                </StackPanel>
            </VisualBrush.Visual>
        </VisualBrush>
    </TextBox.Background>
</TextBox>

      

It looks like this:

enter image description here

However, when I remove the property Background

, the text is stretched like this:

enter image description here

Is there a way to add a background without changing the way the text is displayed?

+3


source to share


2 answers


the desktop of this problem, which I don't know why this is happening, would be to remove the Background property from the text block and place it behind it like this.



        <Grid>
            <Rectangle Fill="Blue"/>
            <TextBox Height="100">
                <TextBox.Background>
                    <VisualBrush Stretch="Fill" TileMode="None" AlignmentX="Left" AlignmentY="Top">
                        <VisualBrush.Visual>
                            <StackPanel>
                                <TextBlock Margin="0" Padding="0" Opacity="0.5" Text="155"/>
                            </StackPanel>

                        </VisualBrush.Visual>
                    </VisualBrush>
                </TextBox.Background>
            </TextBox>
        </Grid>

      

0


source


If you use Background="Transparent"

it will use the same layout but no background color. Is this what you are trying to do?



+1


source







All Articles