none
Textbox control ignores vertical text alignment setting!

    Question

  • I cannot vertically align text in a textbox control. Which is funny since you can position text anywhere (top left/right, bottom left/right, center, etc) in a LABEL control…. LOL…

    This has be a common problem out there.... I simply want to be able to position text not only horizontally but also vertically in a textbox control.
     
    The possible properties I have to choose from are:
    1) TextAlignment (this works but only for horizontal text alignment)
    2) VerticalContentAlignment(settings for top, center, bottom or stretch but ignores any setting here)
    3) HorizontalContentAlignment(settings for left, center, right or stretch but ignores any setting here)
     
    <TextBox Canvas.Left="211" Canvas.Top="156" Height="36" Name="textBox1" Width="173" Text="Text will go here...." HorizontalContentAlignment="Left" FontFamily="Arial" FontSize="14" FontWeight="Bold" TextAlignment="Left" UseLayoutRounding="False" BorderThickness="2" BorderBrush="Black" VerticalContentAlignment="Center" IsHitTestVisible="False" />
     
    Why have a property listed that doesn't work? LOL. Anyone have an answer?
     
    Mike in Los Angeles

     

     

    Thursday, July 22, 2010 1:54 PM

Answers

  • Hi Mike.

    Why have a property listed that doesn't work? LOL. Anyone have an answer?


    That property is not from the TextBox, but one of its base classes. That is why every control lists it, even if it is not supported. From the documentation: "This property only affects a control whose template uses the VerticalContentAlignment property as a parameter. On other controls, this property has no impact."

    I don't think aligning the text vertically in the text box is supported in Silverlight. Maybe a solution is to let the text box grow automatically (wrap the text and set the height to auto), and put it in a container where it is centered vertically? I.e. not centering the text in the text box, but centering the text box itself?

    Friday, July 23, 2010 2:28 AM
  • If you are looking for a solution, you can modify the template of the text box and template bind the content presenter (in this case ScrollContentPresenter) to VerticalContentAlignment. Then when you set the VerticalContentAlignment to center your text will be vertically centered. If you do not what to modify the template, you can adjust the padding (add padding to top) to move the text down till it is visually centered.

    Kevin

    Friday, July 23, 2010 9:48 AM

All replies

  • Hi Mike.

    Why have a property listed that doesn't work? LOL. Anyone have an answer?


    That property is not from the TextBox, but one of its base classes. That is why every control lists it, even if it is not supported. From the documentation: "This property only affects a control whose template uses the VerticalContentAlignment property as a parameter. On other controls, this property has no impact."

    I don't think aligning the text vertically in the text box is supported in Silverlight. Maybe a solution is to let the text box grow automatically (wrap the text and set the height to auto), and put it in a container where it is centered vertically? I.e. not centering the text in the text box, but centering the text box itself?

    Friday, July 23, 2010 2:28 AM
  • If you are looking for a solution, you can modify the template of the text box and template bind the content presenter (in this case ScrollContentPresenter) to VerticalContentAlignment. Then when you set the VerticalContentAlignment to center your text will be vertically centered. If you do not what to modify the template, you can adjust the padding (add padding to top) to move the text down till it is visually centered.

    Kevin

    Friday, July 23, 2010 9:48 AM
  • its almost 2 years since this post

    and this is just a rant but

    since WinForms microsoft is unable to make common sense Basic Controls

    one can do it almost right in WPF

    but Silverlight blows ones mind of how imature it is in many ways...

    even if we learn histroy we learn nothing from it

    way to destroy a potentially great "technology"

    MS.Internal.TextBoxView ... are you kidding me

    sorry for not being constructive

    Monday, April 02, 2012 10:11 PM