Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make TextBox scrollable in WPF

I using one header control in wpf application in that I am using Grid and in that grid I am putting List box some buttons and text box. I want to make that text box scrollable. Can you please give me the solution

like image 967
jolly Avatar asked Mar 27 '26 08:03

jolly


1 Answers

For a TextBox, set its following properties:

<TextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto"/>

You said:

I have tried this but it is not working

<Label Content="Log Details" Grid.Row="4" ></Label>
<Border Margin="7,7,7,3" Grid.Row="5">
  <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="5" > 
    <StackPanel >
      <TextBox Margin="5" AcceptsReturn="True"
               VerticalScrollBarVisibility="Visible" IsReadOnly="True" 
               x:Name="LogDetails" /> 
    </StackPanel>
  </ScrollViewer>
</Border>

I am putting this in headercontrol. – jolly

Actually, you don't need to put a TextBox into a ScrollViewer since TextBox already has a ScrollViewer associated in its Template.

But if you are having your specific requirement in which you need to do the same, you can try something like this:

<Label Content="Log Details" Grid.Row="4" ></Label>
<Border Margin="7,7,7,3" Grid.Row="5">
  <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="5" >
    <StackPanel>
      <TextBox Margin="5" TextWrapping="Wrap"
               AcceptsReturn="True" IsReadOnly="True"
               x:Name="LogDetails" />
    </StackPanel>
  </ScrollViewer>
</Border>
like image 136
viky Avatar answered Mar 30 '26 01:03

viky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!