我们如何在 Windows Phone 中设置 TextBlock 的背景图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4779816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do we set background image of TextBlock in Windows Phone?
提问by Altaf
I am facing problem in setting the background of textblock in Windows Phone.
我在 Windows Phone 中设置文本块背景时遇到问题。
<TextBlock Text="Forget Password" Height="19" Width="156">
采纳答案by Boryana Miloshevska
You can try this:
你可以试试这个:
<Grid>
<Grid.Background>
<ImageBrush ImageSource="MyImage.jpg" />
</Grid.Background>
<TextBlock Text="Forget Password" />
</Grid>
回答by ColinE
The TextBlock element cannot display a background image. You can display an image behind your TextBlock as follows:
TextBlock 元素无法显示背景图像。您可以在 TextBlock 后面显示图像,如下所示:
<Grid>
<Image Source="..."/>
<TextBlock Text="Forget Password" Height="19" Width="156">
</Grid>
You might have to apply a suitable Margin or padding to your image for this to work.
您可能需要对图像应用合适的边距或填充才能使其工作。
If you want to add images to a number of TextBlocks, you might want to consider re-templating yor TextBlock via a Style.
如果您想将图像添加到多个 TextBlock,您可能需要考虑通过样式重新模板化您的 TextBlock。
回答by AnthonyWJones
You can use a border control to contain the TextBlock
:-
您可以使用边框控件来包含TextBlock
:-
<Border Background="{StaticResource KeyToDesiredBackgroundBrush}">
<TextBlock Text="Forget Password" Height="19" Width="156" />
</Border>