3

I'm trying to create a multi-line TextBox to allow the user to enter text.

I have:

<TextBox Grid.Row="0"
    Height="107"
    ScrollViewer.VerticalScrollBarVisibility="Auto"
    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
    AcceptsReturn="True"
    HorizontalAlignment="Left"
    Margin="164,80,0,0"
    VerticalAlignment="Top"
    Width="237"
    Text="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="300" 
    TextWrapping="Wrap"/>

However the text is centered vertically and I can't seem to find a TextAlignment property for vertical alignment.

I subsequently wrapped the textbox in a border and removed the Height specification, however when I click in the area below the textbox (but within the border) I would like the textbox to get focus and I can't seem to find a way to do this.

Has anyone come across this issue before and found a solution?

6
  • 4
    It's silly question, but have you tried to set the VerticalContentAlignment? Commented Dec 5, 2012 at 13:57
  • Hi Nick ! With this xaml only, I can't reproduce your issue. What version of .NET are you using ?
    – Sisyphe
    Commented Dec 5, 2012 at 13:59
  • @ViktorLaCroix, thank you very much. This is exactly what I was looking for but failed to find. If you add your comment as an answer, I'll accept it to give you the points!
    – Nick
    Commented Dec 5, 2012 at 14:35
  • @Nick it's ok. It does not answer second part of your question anyway ;) Commented Dec 5, 2012 at 14:47
  • try VerticalContentAlignment = stretch
    – paparazzo
    Commented Dec 5, 2012 at 15:20

1 Answer 1

7

So after discussion in comments. This is the Answer:

<TextBox Height="107"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
AcceptsReturn="True"
HorizontalAlignment="Left"
Margin="657,237,0,0"
VerticalAlignment="Top"
Width="237"
Text="Text alignment left and top" MaxLength="300" 
TextWrapping="Wrap" VerticalContentAlignment="Top" HorizontalContentAlignment="Left"/>

No question should be left unanswered! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.