WPF - 如何停止TextBox的自动大小? [英] WPF - How to stop TextBox from autosizing?
问题描述
-
窗口
I have a textbox in my visual tree as follows..
我的可视化树中有一个文本框,如下所示。 c $ c
$ ul
$网格
-
ListBox
-
ItemTemplate
-
DataTemplate
-
网格
-
网格
-
文本框
... Window
Grid
ListBox
ItemTemplate
DataTemplate
Grid
Grid
Textbox
...
<TextBox Height="Auto" Text="{Binding Path=LyricsForDisplay}" MinHeight="50" MaxHeight="400" Visibility="Visible" VerticalScrollBarVisibility="Auto" IsReadOnly="True" AllowDrop="False" TextWrapping="WrapWithOverflow"> </TextBox>
当长文本被添加到绑定变量(LyricsForDisplay)时,列表框中的所有项目都会展开它们textboxes / grids的宽度,以允许整个字符串被看到,如果你使用滚动条在底部显示...
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?
推荐答案
以下工作:
The following works:
<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
。这篇关于WPF - 如何停止TextBox的自动大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-
-
-
-
-
-