i have taken a textbox
<TextBox Height="218" HorizontalAlignment="Stretch" Margin="0,56,0,0" Name="txtBox" VerticalAlignment="Top" TextWrapping="Wrap"
Text="" GotFocus="txtBox_GotFocus" TextChanged="txtBox_TextChanged" IsTabStop="True"
IsEnabled="True" IsHitTestVisible="True" VerticalScrollBarVisibility="Auto" Background="White" FontFamily="Tahoma" />
Now when i enter lot of text in textbox then text scrolled up automatically. I want to show a scrollbar with which user can surf to the whole text. How to do this.
Approach: To create a responsive scroll box, add a <div> tag and then proceed to create the scroll box. All you need to do is to choose the height and width of the scroll box (make sure that the height of your box is short enough so that you have an overflow of the text, allowing box to scroll down.
An HTML scroll box is a box that grows scroll bars when it's contents are too large to fit in the box. How do you make the box? You create the box using a normal HTML element (such as the div element). Then, to make the box scroll, you apply the CSS overflow property to the div.
Scroll in a DocumentClick the arrow buttons at the top, bottom, and sides of the scroll bar to scroll one line at a time. Click and drag a scroll bar to move quickly though a document, releasing it when you've reached the page you want.
You could use a simple ScrollViewer
, like this:
<ScrollViewer Height="219" VerticalScrollBarVisibility="Auto">
<TextBox VerticalAlignment="Top" TextWrapping="Wrap" Height="Auto" HorizontalAlignment="Left" Name="textBox1" Text="TextBox" Width="460">
</TextBox>
</ScrollViewer>
That's in case the text is entered vertically. You could do the same for horizontal scrolling but this method is not quite reliable due to the fact that it doesn't scroll automatically with the default implementation (like I showed).
Generally, I would simply recommend overriding the template for the default control.
There isn't a simple solution to this problem. Additionally, if you are allowing someone to enter a large amount of text it's possible that as they add more lines you coudl reach the height limit (2048px) imposed on UIElements.
If you need users to be able to enter a large amount of text you should consider putting an Input
element inside a WebBrowser
control and using that for the field instead.
Two simple steps to go for this:
- Create
TextBox_TextInputStart
event handler.- assuming your scrollviewer is named as
sv
and textbox is named astxtbx
, add the following lines in the event handler method
this.sv.UpdateLayout();
this.sv.ScrollToVerticalOffset(this.txtbx.ActualHeight);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With