0
A
回答
1
定义WrapPanel
为ListBox
的ItemsPanel
:
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel ></WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
不要忘记设置Width
或MaxWidth
到画布面板。一旦达到最大宽度,它将开始将内容放置在新线上...
+0
这似乎工作,但我没有得到任何滚动条? –
0
使用宽度设置为值的WrapPanel。对于例如运行下面的代码:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525" >
<Window.DataContext>
<local:ParentViewModel />
</Window.DataContext>
<ListBox Height="auto" ItemsSource="{Binding MyList,Mode=TwoWay}">
<ListBox.Style>
<Style TargetType="{x:Type ListBox}">
<Setter Property="ItemTemplate" >
<Setter.Value>
<DataTemplate>
<Button Content="{Binding}" Padding="15,5" Margin="100,40,0,0"
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBox}},Path=DataContext.RemoveButtonCommand}"
CommandParameter="{Binding}"
/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Style>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}},Path=ActualWidth}"
>
</WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
您将获得垂直和水平滚动条。都根据窗口的高度和宽度用listbox中的元素进行调整。 (请绑定你自己的列表框源代码)
相关问题
- 1. 在DataGridView图像列中显示多个图像?可能吗?
- 2. 图像不能显示在列表中
- 3. 在列表视图中显示图像
- 4. 在列表视图中显示图像
- 5. Android:显示具有多个列和行的图像(nxn)。有内存问题
- 6. WPF列表框不会显示包装在多列中的图像
- 7. 无法在Silverlight中的列表框控件中显示图像
- 8. 未在用户控件的列表框中显示图像
- 9. Windows Phone在绑定的列表框中显示RSS图像
- 10. 是否有可能在食谱中显示图像直方图
- 11. 在表格的某些列中显示具有空值的行
- 12. fpdf使用多列单元格的表格行显示图像
- 13. 绑定后图像不显示在列表框中
- 14. 仅在列表框中显示图像文件扩展
- 15. C#如何在列表框中循环显示图像
- 16. 在新闻稿中的多个表格行上显示图像
- 17. 具有透明图像的CSS边框图像在Android上显示边缘
- 18. 显示图像列表
- 19. 无法显示列表中的图像
- 20. 在数据表列显示的图像
- 21. 显示在列表旁边的图像
- 22. 在行中显示图像
- 23. 具有多个复选框和图像的列表视图视图?
- 24. 在列表框中显示消息框中的多个信息
- 25. 我试图显示在列表视图图像的列表,但
- 26. 如何在列表框中显示所有单词时显示在单行中
- 27. 显示工具提示中的图像
- 28. VB.NET如何仅在可见的图片框中显示图像
- 29. 在列表框中突出显示多个项目/行
- 30. 显示列表框中的图像保持文件锁定
ListView可以帮助你 –
@不幸我现在来看看这个,谢谢你回到我身边。 –