问题描述
我在 App.xaml 中定义了以下样式
I have the following style defined in my App.xaml
<Style x:Key="textBoxMultiline" TargetType="{x:Type TextBox}" >
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="MinHeight" Value="50" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
在整个解决方案中,我们在需要简短文本的每个文本框上都使用它.
And throughout the solution we're using it on every text box that needs a brief text.
<TextBox x:Name="textBoxDescription" Grid.Row="2" Grid.Column="1" Style="{DynamicResource textBoxMultiline}" />
一切都很好,但随后客户抱怨某些字段在分辨率较低的旧显示器上堆积,因此我在较高的可视化树节点之一上放置了 ScrollViewer
以防止堆积.
Everything works great, but then the client complains about some fields were corped on older monitors with lower resolutions, so I placed a ScrollViewer
on one of the higher visual tree nodes to prevent the corping.
<ScrollViewer Height="Auto" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
...
</ScrollViewer>
奇怪的是,具有上述样式的 TextBox
开始向右扩展而不是包裹文本.
Strangely, the TextBox
es with the above style start expanding to the right instead of wrapping the text.
有没有办法在不删除 ScrollViewer
的情况下防止这种情况发生?
Is there a way to prevent this without removing the ScrollViewer
?
推荐答案
你必须为 TextBox
定义一个 MaxWidth
,否则没有限制,因为 ScrollViewer
.
You must define a MaxWidth
for the TextBox
, otherwise there's no limit because the ScrollViewer
.
这篇关于防止文本框在 WPF 中水平扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!