列表框项目模板的宽度... [英] Listbox Itemtemplate width...
问题描述
我有一个带有列表框的窗口.在列表框itemtemplate中,我有一个填充宽度的文本框.但是我似乎无法做的是让文本框换行,而不是超出列表框的宽度.文本框变宽,列表框变水平.有没有简单的方法可以做到这一点?
I've got a window with a listbox filling it. And in the listbox itemtemplate i have a textbox that fills the width. But what i cant seem to do is to have the textbox wrap instead of growing past the width of the listbox. The textbox gets wider and the listbox gets a horizontal scrollbar. Is there an easy way to do this?
到目前为止,这是我的XAML:
Here is my XAML so far:
< ListBox 名称 = " 列表 " ItemsSource = " {Binding Path = SimonData} " 边距 = &; 0,0,0,0 " HorizontalContentAlignment = " 拉伸 " > >
<ListBox Name="list" ItemsSource="{Binding Path=SimonData}" Margin="0,0,0,0" HorizontalContentAlignment="Stretch">
< ListBox.ItemTemplate >
<ListBox.ItemTemplate>
< DataTemplate >
<DataTemplate>
< StackPanel 边距 = " 0,0,0,0 " >
<StackPanel Margin="0,0,0,0">
< TextBlock 文本 = " {Binding Path = id} " />
<TextBlock Text="{Binding Path=id}"/>
< 文本框 名称 = " txt " 接受退货 = " True " 文本 = " {Binding Path = notes,Mode = TwoWay} " 边距 = " 0,0,0,0 ""; MaxLines = " 8 " VerticalScrollBarVisibility = " 自动 " > TextWrapping = " WrapWithOverflow " />
<TextBox Name="txt" AcceptsReturn="True" Text="{Binding Path=notes, Mode=TwoWay}" Margin="0,0,0,0" MaxLines="8" VerticalScrollBarVisibility="Auto" TextWrapping="WrapWithOverflow"/>
</ StackPanel >
</StackPanel>
</ DataTemplate >
</DataTemplate>
</ ListBox.ItemTemplate >
</ListBox.ItemTemplate>
</ ListBox >
感谢您的帮助.谢谢.
Trevor Dunsford
推荐答案
尝试类似的操作
try something like this
< 文本块 文本 = " {Binding Name} " TextWrapping = &; WrapWithOverflow <字体大小= 1>" <字体颜色=#0000ff"大小= 1> <字体颜色=#ff0000"大小= 1>宽度 <字体颜色=# 0000ff"size = 1> = " 125 " 字体>
<TextBlock Text="{Binding Name}" TextWrapping="WrapWithOverflow" Width="125"
ScrollViewer.CanContentScroll = " ; 否 &; ScrollViewer.HorizontalScrollBarVisibility = " 已禁用 " ></ 文本块 >
ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled"></TextBlock>
这篇关于列表框项目模板的宽度...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!