How do we set background image of TextBlock in Windows Phone?

我与影子孤独终老i 提交于 2020-01-14 09:46:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!