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屋!
查看全文