水平排列项目的 WPF ListBox [英] WPF ListBox that lays out its items horizontally
本文介绍了水平排列项目的 WPF ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个 WPF 应用程序来显示选择中的图像.我想在窗口顶部的横幅中显示所有可用图像,并在主窗口中显示主要选定图像以供进一步处理.
I'm trying to write a WPF application for displaying images from a selection. I want to display all of the available images in a banner along the top of the window, and display the main selected image in the main window for further processing.
如果我想要在窗口的左侧的列表,垂直显示图像,我可以使用数据绑定非常优雅地做到这一点.
If I wanted the list on the Left of the window, displaying the images vertically, I can do this quite elegantly using databinding.
<ListBox
Name="m_listBox"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Width="60" Stretch="Uniform" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
有没有一种直接的方法可以使这个水平而不是垂直?解决方案的主要要求是:
Is there a straightforward way I can make this horizontal instead of vertical? The main requirements of a solution is:
- 使用数据绑定填充项目
- 所选项目只需通过用户点击即可更改.
推荐答案
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem>listbox item 1</ListBoxItem>
<ListBoxItem>listbox item 2</ListBoxItem>
<ListBoxItem>listbox item 3</ListBoxItem>
<ListBoxItem>listbox item 4</ListBoxItem>
<ListBoxItem>listbox item 5</ListBoxItem>
</ListBox>
这篇关于水平排列项目的 WPF ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文