[UWP]当Textwraps或返回键按下时,防止在ScrollViewer中自动滚动到TextBox顶部 [英] [UWP]Prevent Autoscroll to Top of TextBox in ScrollViewer When Textwraps or Return Key Pressed

查看:148
本文介绍了[UWP]当Textwraps或返回键按下时,防止在ScrollViewer中自动滚动到TextBox顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:


我在ScrollViewer中有一个文本框,其中包含  TextWrapping =" Wrap"和AcceptsReturn =" True"。 当我在文本框中输入足够的文本以便我必须向下滚动滚动查看器以保持文本可见时,如果我输入足够的
文本以导致文本包装,或者如果我点击返回键,则会显示scrollviewer autoscrolls到顶部。 我希望能够输入文本(并使用返回键),而不会在文本换行或返回键
被击中时滚动查看器跳到顶部。 有没有办法避免这种行为?


这里有一些非常简单的示例代码可以重现这个问题。 键入文本框,直到有足够的文本/返回,以便您必须向下滚动才能查看您正在键入的文本(例如,就像您只是键入并填充文本框一样,
滚动查看文本,因为您型)  然后,如果您输入足够的文本来填充一行并导致文本换行或点击返回键 要获得一个新行来输入文本,滚动查看器似乎跳到顶部,输入的
文本的插入点现在不可见(在滚动查看器的底部)。 无论您在滚动查看器中的哪个位置导致换行或点击返回键,滚动查看器都会跳到顶部。





< pre class ="prettyprint"style ="">< ScrollViewer Height =" 100"宽度= QUOT; 100" >
< TextBox TextWrapping =" Wrap" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 100" BorderBrush = QUOT;透明"了borderThickness = QUOT; 0" AcceptsReturn = QUOT;真" />
< / ScrollViewer>


解决方案

嗨  rTolder,


据我所知,当我们将TextWrapping设置为Wrap时,我们不需要在ScrollViewer中设置TextBox。它可以滚动。您应该为TexteBox设置高度。


当我们在ScrollView中添加TextBox时,有两个ScrollViewers。为了避免这种行为,我们应该能够删除ScrollViewer。


例如:

< TextBox Height =" ; 100" TextWrapping = QUOT;包覆与QUOT; VerticalAlignment = QUOT;陀螺"宽度= QUOT; 100" BorderBrush = QUOT;透明"了borderThickness = QUOT; 0" AcceptsReturn = QUOT;真" /> 




最好的问候,


Jayden Gu


Hi All:

I have a Textbox in a ScrollViewer with TextWrapping="Wrap" and AcceptsReturn="True".  When I enter enough text into the textbox to so that I have to scroll the scrollviewer down to keep the text visible, if I then type enough text to cause a textwrap or if I hit the return key it appears the scrollviewer autoscrolls to the top.  I would like to be able to enter text (and use the return key) without having the scrollviewer jump to the top when the text wraps or the return key is hit.  Is there a way to avoid this behavior?

Here's some very simple sample code that reproduces the issue.  Type into the textbox until there is enough text/returns so that you have to scroll down to view the text you are typing (e.g., as if you were simply typing and filling the textbox and scrolling to view the text as you type).   If you then type enough text to fill a line and cause a textwrap or hit the return key  to get a new line to type text on, the scrollviewer seems to jump to the top, and the insertion point where your text in entered is now not visible (off the bottom of the scrollviewer).  The scrollviewer jumps to the top no matter where in the scrollviewer you cause the wrap or hit the return key.


<ScrollViewer Height="100" Width="100" >
            <TextBox TextWrapping="Wrap" VerticalAlignment="Top" Width="100" BorderBrush="Transparent" BorderThickness="0" AcceptsReturn="True"/>
</ScrollViewer>


解决方案

Hi rTolder,

As far as I known, when we set the TextWrapping to Wrap, we do not need to set the TextBox in the ScrollViewer. It can be scrolled. You should be set the Height for the TexteBox.

When we add the TextBox in the ScrollView, that there are two ScrollViewers. To avoid this behavior, we should be able to remove the ScrollViewer.

For example:

<TextBox Height="100" TextWrapping="Wrap" VerticalAlignment="Top" Width="100" BorderBrush="Transparent" BorderThickness="0" AcceptsReturn="True" />


Best Regards,

Jayden Gu


这篇关于[UWP]当Textwraps或返回键按下时,防止在ScrollViewer中自动滚动到TextBox顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆