TextBlock的背景属性去掉弹力 [英] TextBlock Background Property removing stretch
本文介绍了TextBlock的背景属性去掉弹力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义为这样一个TextBox:
I have a TextBox defined as 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:
然而,当我删除背景
属性,文本延伸是这样的:
However, when I remove the Background
property, the text stretches like this:
有什么办法来添加背景不改变文字看起来?
Is there any way to add the background without changing the way the text looks?
推荐答案
这个问题的workarround,我不知道为什么它的发生是从文本块去除背景财产,并把它的背后是这样
a workarround of this problem which i don't know why it occurs would be to remove Background property from textblock and put 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>
这篇关于TextBlock的背景属性去掉弹力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文