【发布时间】:2012-05-16 22:15:50
【问题描述】:
我花了两个小时研究如何避免我的 WPF 文本框控件在输入长文本时增长,但我无法做到这一点,即使我已经阅读了一些类似的答案:
stopping-wpf-textbox-from-growing-with-text
wpf-allow-textbox-to-be-resized-but-not-to-grow-on-user-input
wpf-how-to-stop-textbox-from-autosizing
我的代码如下:
<Grid>
<TextBox Margin="6,6,8,28" Name="textBox1" AcceptsTab="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True"/>
<CheckBox Content="Case sensitive" HorizontalAlignment="Left" Margin="7,0,0,2" Name="checkBox1" Height="16" VerticalAlignment="Bottom" />
</Grid>
我尝试过的一件事是:
MaxWidth={Binding ElementName=MyGrid, Path=ActualWidth}
但它对我不起作用。
我还尝试将以下属性添加到 Grid:
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
或者
<Border x:Name="b" Grid.Column="1"/>
<TextBox Width="{Binding ActualWidth, ElementName=b}" ....... />
但它也不起作用。
当用户拉伸窗口时,我需要我的控件来增长,而不是在插入长文本时。
对于这个问题你有什么不同的答案我可以试试吗?
更新!
我注意到一些非常奇怪的事情:如果我手动拉伸窗口,当插入长文本时,文本框会停止增长。没关系。但是我需要在每次运行程序时都不必拉伸窗口来实现这一点
【问题讨论】:
-
找到解决方案了吗?