问题
I am facing problem in setting the background of textblock in Windows Phone.
<TextBlock Text="Forget Password" Height="19" Width="156">
回答1:
You can try this:
<Grid>
<Grid.Background>
<ImageBrush ImageSource="MyImage.jpg" />
</Grid.Background>
<TextBlock Text="Forget Password" />
</Grid>
回答2:
The TextBlock element cannot display a background image. You can display an image behind your TextBlock as follows:
<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.
回答3:
You can use a border control to contain the TextBlock
:-
<Border Background="{StaticResource KeyToDesiredBackgroundBrush}">
<TextBlock Text="Forget Password" Height="19" Width="156" />
</Border>
来源:https://stackoverflow.com/questions/4779816/how-do-we-set-background-image-of-textblock-in-windows-phone