locked
how can i add image in textblock RRS feed

  • Question

  • hi Team ,

    Q1)i wanted to know that is it possible to add image in textblock from xaml side?

    Q2)how can i underline the textblock in silverlight through xaml ?

    thanks in advance

    Monday, October 17, 2011 12:36 AM

Answers

  • Hi,

    You can add an image in text block.

    use like this...

     <TextBlock x:Name="mybloxk" Text="City" Grid.Row="1" Grid.Column="1" Height="68"  FontSize="56" Width="116">
                    <TextBlock.Foreground>                   
                    <ImageBrush ImageSource="CF_logo.png" />           
                    </TextBlock.Foreground>
        </TextBlock>

    for underline use like this...
     <TextBlock TextDecorations="Underline" x:Name="mybloxk" Text="City" Grid.Row="1" Grid.Column="1" Height="68"  FontSize="56" Width="116">
                    <TextBlock.Foreground>                   
                    <ImageBrush ImageSource="CF_logo.png" />           
                    </TextBlock.Foreground>
                </TextBlock>
    Monday, October 17, 2011 3:05 AM

All replies

  • Hello Mohan,

    Ans1) I don't think it is possible to add image in textblock.

    If you want to add background image on textblock see 

    http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/7237/

    or i you want to add image and textblock in same place you can use stack panel.

    like this button example http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx

    Ans 2) you can do it like this

    <TextBlock TextDecorations="Underline">My Underlined Text</TextBlock>

    Thanks.

     

    Monday, October 17, 2011 2:40 AM
  • Hi,

    You can add an image in text block.

    use like this...

     <TextBlock x:Name="mybloxk" Text="City" Grid.Row="1" Grid.Column="1" Height="68"  FontSize="56" Width="116">
                    <TextBlock.Foreground>                   
                    <ImageBrush ImageSource="CF_logo.png" />           
                    </TextBlock.Foreground>
        </TextBlock>

    for underline use like this...
     <TextBlock TextDecorations="Underline" x:Name="mybloxk" Text="City" Grid.Row="1" Grid.Column="1" Height="68"  FontSize="56" Width="116">
                    <TextBlock.Foreground>                   
                    <ImageBrush ImageSource="CF_logo.png" />           
                    </TextBlock.Foreground>
                </TextBlock>
    Monday, October 17, 2011 3:05 AM
  • Hi,

    I think you cannot add image inside a textblock, May i know the reason for enclosing image in textbloxk, u can make use of border with Image within it .

    Ans2) Silverlight 4 comes with one type of text decoration. i.e underline , set TextDecorations="underline" . u shud bee underline for text in textblock. For various format of text within textblock u can make use of "RUN"

           <TextBlock >
                <Run FontWeight="Bold">Hi World.</Run>            
            </TextBlock>

    Monday, October 17, 2011 3:26 AM