WPF - 如何阻止文本框自动调整大小? [英] WPF - How to stop TextBox from autosizing?
问题描述
我的视觉树中有一个文本框,如下所示..
I have a textbox in my visual tree as follows..
窗口
网格
列表框
项目模板
数据模板
网格
网格
文本框
...
<TextBox Height="Auto" Text="{Binding Path=LyricsForDisplay}" MinHeight="50" MaxHeight="400" Visibility="Visible" VerticalScrollBarVisibility="Auto" IsReadOnly="True" AllowDrop="False" TextWrapping="WrapWithOverflow"> </TextBox>
当长文本被添加到绑定变量 (LyricsForDisplay) 时,列表框中的所有项目都会扩展它们的文本框/网格宽度,以便在您使用底部出现的滚动条时看到整个字符串...
When long text is added to the bound variable (LyricsForDisplay) all of the items in the listbox expand their textboxes/grids width's to allow for the entire string to be seen if you use the scrollbar on bottom that appears...
我想做的是让框/网格仅在用户拉伸窗口时才调整大小..而不是在输入长文本时(它可能只是环绕..)
What I would like to do is make it so the boxes/grids only resize if the user stretches the window .. NOT when a long text is entered (it could just wrap around..)
有谁知道如何获得该功能?
Does anyone know how to obtain the functionality?
推荐答案
以下作品:
<ListBox Name="ListBox1" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid> <TextBox TextWrapping="Wrap"></TextBox> </Grid> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
注意
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
和TextWrapping="Wrap"
的使用.Notice the use of
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
andTextWrapping="Wrap"
.这篇关于WPF - 如何阻止文本框自动调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!