Ask a questionAsk a question
 

AnswerFontWeight property doesn't work on TextBlock

  • Wednesday, April 18, 2007 2:43 PMwendy5 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    hi, i have some issues with the FontWeight (and the FontStyle too) property ...

    does anybody have those properties working ??

     

    here is my code:

    <TextBlock FontSize='12' TextWrapping='Wrap' Width='300' Height='Auto' Canvas.Left='10' Canvas.Top='55'><Run FontWeight="Bold">hello</Run></TextBlock>

     

     

    thanks

Answers

  • Wednesday, April 18, 2007 7:06 PMMark Rideout Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer


    The default font doesn't support anything other than normal weight and style. You need to specify a different font family such as Verdana. Also Height='auto' doesn't work/do anything and will probably be a parse error in newer bits. See this link for a list of supported fonts: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1056996&SiteID=1

    If a font doesn't support a weight or style we currently (for v1) do not generate algorithmic bolded/italic versions of that font. This is why specifying Bold with the default font doesn't do anything.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


     

     

All Replies

  • Wednesday, April 18, 2007 3:08 PMChad CampbellMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Wendy,

      

    You can set the "FontWeight" property of the "TextBlock" element.  Simply say

     

    Code Snippet
    <TextBlock ... FontWeight="Bold" ... />

     

    Please refer to the Silverlight SDK for the TextBlock element for more information.  The Silverlight SDK for the TextBlock element is available here: http://msdn2.microsoft.com/en-us/library/bb188394.aspx

     

    If this answers your question, please select "Mark as Answer" otherwise, please post a followup question.

     

    Thank you,

    Chad Campbell

  • Wednesday, April 18, 2007 3:19 PMwendy5 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    i know but this doesn't work either... :-(
  • Wednesday, April 18, 2007 3:29 PMChad CampbellMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Wendy,

     

    I definately see you problem.  I just attempted the following:

     

    Code Snippet

    <Canvas xmlns="http://schemas.microsoft.com/client/2007"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <TextBlock FontWeight="Normal" Text="Normal" />

    <TextBlock Canvas.Top="20" FontWeight="ExtraBold" Text="Bold" />

    </Canvas>

     

     Unfortunately, it didn't work.  It might be a bug in the current CTP
  • Wednesday, April 18, 2007 4:02 PMWynApse Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Good point, Chad...

     

    I went back and looked at some old code, because I could swear I'd used FontWeight, and I have FontWeight="900" on a few things that when I just changed it to "100", it didn't do anything. I'd like to think it did something when I wrote it, but at this point in time, it's hard telling.

     

    At any rate, FontWeight doesn't appear to do anything now!

     

    -Dave

  • Wednesday, April 18, 2007 7:06 PMMark Rideout Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer


    The default font doesn't support anything other than normal weight and style. You need to specify a different font family such as Verdana. Also Height='auto' doesn't work/do anything and will probably be a parse error in newer bits. See this link for a list of supported fonts: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1056996&SiteID=1

    If a font doesn't support a weight or style we currently (for v1) do not generate algorithmic bolded/italic versions of that font. This is why specifying Bold with the default font doesn't do anything.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


     

     

  • Thursday, April 19, 2007 7:54 AMwendy5 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    thanks for the answer, but i tried to use a FontFamily (Arial or Verdana) and it doesn't do anything...

     

    <TextBlock FontFamily="Verdana"  FontWeight="Bold" TextWrapping='Wrap' Width='300' Canvas.Left='10' Canvas.Top='55'>hello</TextBlock>

  • Thursday, April 19, 2007 12:59 PMWynApse Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Wendy...

     

    Give this a shot:

     

    <TextBlock FontFamily="Verdana"  FontWeight="Bold" TextWrapping="Wrap" Canvas.Left="10" Canvas.Top="55" Text="hello" />

     

    The Text= is inside the tag, and everything is double-quoted. I left off Width, I'm not sure it does anything in TextBlock.

     

    Hope this helps!

     

    -Dave