Search code examples
c#.netwpfxamltextbox

A Multi-Line TextBox with Top Vertical Alignment


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?


Solution

  • 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! :)