Altaf
Altaf

Reputation: 5170

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

I am facing problem in setting the background of textblock in Windows Phone.

<TextBlock Text="Forget Password" Height="19" Width="156">

Upvotes: 5

Views: 7796

Answers (3)

Boryana Miloshevska
Boryana Miloshevska

Reputation: 2730

You can try this:

<Grid>
 <Grid.Background>
    <ImageBrush ImageSource="MyImage.jpg" />
 </Grid.Background>
 <TextBlock Text="Forget Password" />
</Grid>

Upvotes: 3

AnthonyWJones
AnthonyWJones

Reputation: 189457

You can use a border control to contain the TextBlock:-

<Border Background="{StaticResource KeyToDesiredBackgroundBrush}">
   <TextBlock Text="Forget Password" Height="19" Width="156" />
</Border>

Upvotes: 5

ColinE
ColinE

Reputation: 70142

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.

Upvotes: 6

Related Questions