[英]Horizontal scroll bar doesn't appear on TextBox
I have a Grid which has a TextBox inside a ScrollViewer: 我有一个在ScrollViewer内部有一个TextBox的网格:
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ScrollViewer>
<StackPanel Height="271" Width="258">
<Label FontSize="15" Margin="10"> Suggestions </Label>
<Expander x:Name="expander" Margin="10" />
</StackPanel>
</ScrollViewer>
<GridSplitter Grid.Column="0" Width="5" />
<ScrollViewer Grid.Column="1">
<TextBox x:Name="textBox" AcceptsReturn="True"
AcceptsTab="True" FontSize="15"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Visible"
TextWrapping="WrapWithOverflow" Language="en-US"
SpellCheck.IsEnabled="True"/>
</ScrollViewer>
</Grid>
Even if I set HorizontalScrollBarVisibility to Visible, the horizontal scroll bar is not visible, and when I type some text that goes beyond the TextBox's width, I can't scroll: 即使将HorizontalScrollBarVisibility设置为Visible,水平滚动条也不可见,并且当我键入一些超出TextBox宽度的文本时,将无法滚动:
Looking at the implementation of the TextBox: http://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/TextBox.cs#1473 查看文本框的实现: http : //referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/TextBox.cs#1473
it seems that this is the normal behavior: the horizontal scrollbar is not visible when TextWrapping is WrapWithOverflow. 看来这是正常现象:当TextWrapping为WrapWithOverflow时,水平滚动条不可见。
Based on that, the only possible way to show the horizontal scrollbar of the TextBox is to set the TextWrapping to NoWrap. 基于此,显示TextBox的水平滚动条的唯一可能方法是将TextWrapping设置为NoWrap。
A workarount to what (I think that) you want to achieve with the outer ScrollViewer might be: 想要通过外部ScrollViewer实现的(我认为)工作是:
<ScrollViewer Grid.Column="1" HorizontalScrollBarVisibility="Visible">
<TextBox x:Name="textBox" AcceptsReturn="True"
AcceptsTab="True" FontSize="15"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Hidden"
TextWrapping="WrapWithOverflow" Language="en-US"
SpellCheck.IsEnabled="True"/>
</ScrollViewer>
It appears to me that the TextBox element is not being entirely displayed. 在我看来,TextBox元素并未完全显示。 I'd bet that the scroll bar is there, you just cannot see it without re-sizing your current window or scrolling downwards in the main window.
我敢打赌,滚动条在那里,除非重新调整当前窗口的大小或在主窗口中向下滚动,否则您将看不到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.