locked
TextBlock not displaying text RRS feed

  • Question

  • For some strange reason, I cannot get a TextBlock to display text, yet if I change it to a TextBox, it works just fine.       

    This does not display:

    <TextBlock Height="23" HorizontalAlignment="Left" Margin="130,0,0,188" Name="textBlock1" 
                       Text= "Garbage" VerticalAlignment="Bottom" Width="350" />

    Yet this does:

    <TextBox Height="23" HorizontalAlignment="Left" Margin="130,0,0,188" Name="textBlock1" 
                       Text= "Garbage" VerticalAlignment="Bottom" Width="350" />


    Bill Behning

    Tuesday, June 19, 2012 1:46 PM

Answers

  • Change the Foreground color to make sure it's not the same as the background.  White on White would be hard to see :)
    • Proposed as answer by KP_SES Monday, June 25, 2012 11:13 AM
    • Marked as answer by Kee Poppy Thursday, June 28, 2012 7:00 AM
    Tuesday, June 19, 2012 2:40 PM
  • Bill,

    I just copied your code into my Visual Studio and it works fine ! Just had to change the name of the TextBox (otherwise two controls would have the same name) and the HorizontalAlignment and I can see both controls.

    Must be some other reason...

    • Proposed as answer by Jie Bao Monday, June 25, 2012 10:06 AM
    • Marked as answer by Kee Poppy Thursday, June 28, 2012 7:00 AM
    Tuesday, June 19, 2012 2:25 PM

All replies

  • Bill,

    I just copied your code into my Visual Studio and it works fine ! Just had to change the name of the TextBox (otherwise two controls would have the same name) and the HorizontalAlignment and I can see both controls.

    Must be some other reason...

    • Proposed as answer by Jie Bao Monday, June 25, 2012 10:06 AM
    • Marked as answer by Kee Poppy Thursday, June 28, 2012 7:00 AM
    Tuesday, June 19, 2012 2:25 PM
  • Change the Foreground color to make sure it's not the same as the background.  White on White would be hard to see :)
    • Proposed as answer by KP_SES Monday, June 25, 2012 11:13 AM
    • Marked as answer by Kee Poppy Thursday, June 28, 2012 7:00 AM
    Tuesday, June 19, 2012 2:40 PM
  • That was it.  Although it does not make sense that I have to explicitly set the Foreground color since the default Brushes Foreground is Black in the Properties Window anyway.  Why would it be necessary to set it in XAML?

     <TextBlock Foreground="Black"  Height="23" HorizontalAlignment="Left" Margin="130,0,0,188" Name="textBlock1" 
                       Text= "{Binding Path=FormattedAccountCodeString, Mode=OneWay}" VerticalAlignment="Bottom" Width="350" />


    Bill Behning

    Tuesday, June 19, 2012 3:00 PM
  • Default is black, but it sounds like your TextBlock is getting a style from somewhere.  Perhaps a windows theme...
    Tuesday, June 19, 2012 4:57 PM
  • Hi,

             Can you upload your sample in Skydrive? to solve this


    sivakanth trichy

    Tuesday, June 19, 2012 5:45 PM
  • The two controls have the same name and same location chnage the name and location of the controls... it should work fine
    • Proposed as answer by Jie Bao Monday, June 25, 2012 10:06 AM
    • Marked as answer by Kee Poppy Thursday, June 28, 2012 7:00 AM
    • Unmarked as answer by WRBehning Thursday, June 28, 2012 2:18 PM
    Wednesday, June 20, 2012 9:54 AM
  • No, I was not using both controls at the same time.  I would either use the TextBox or the TextBlock, but not at the same time so one was not positioned on top of the other one.

    Bill Behning

    Thursday, June 28, 2012 2:20 PM
  • That was my case too - nice to find answer 3 years old!
    Wednesday, September 23, 2015 7:39 PM