正如gif所示,我的文本框位于滚动查看器的顶部。但当我向下滚动,并单击空白区域时,文本框总是聚焦在一起。
这很烦人。
如何删除文本框的自动对焦?
<ScrollViewer Grid.Row="1" Padding="5" Style="{StaticResource ScrollViewerAppleStyle}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MinHeight="100" MaxHeight="400"/>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Text="欢迎使用小冰科技最新研发的自然语言处理程序。" x:Name="textInput" x:Uid="textBox_Input" TabIndex="-1" BorderBrush="Gray" BorderThickness="1" TextWrapping="Wrap" AcceptsReturn="True" Style="{StaticResource TransparentBackgroundTextBoxStyle}" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
Other controls.......
</Grid>
</ScrollViewer>
发布于 2018-04-19 20:54:18
我也遇到过这个稍微有点恼人的bug,当与ScrollViewer
结合使用时,它会导致非常不受欢迎的行为。
似乎当您松开一个先前聚焦的控件的焦点时,必须将该焦点分配给另一个控件。TextBox
是页面上第一个“可聚焦”的控件,因此它将是要获得焦点的控件,这会强制ScrollViewer
将其视图更改为定义TextBox
的垂直偏移量。
最简单的选择是处理LostFocus
事件,并将焦点分配给另一个不会引起如此显著问题的控件。
发生这种行为的原因,我猜是为了不破坏只使用键盘的用户的体验。
发布于 2018-12-28 00:16:52
当ScrollViewer的IsTabStop
属性设置为True
时,我也遇到了同样的问题。
<ScrollViewer IsTabStop="True">
//your code with TextBox in here
</ScrollViewer>
https://stackoverflow.com/questions/49917853
复制相似问题