And*_*erd 54 data-binding wpf listbox
我正在尝试编写一个WPF应用程序来显示选择的图像.我希望在窗口顶部的横幅中显示所有可用图像,并在主窗口中显示主要选定图像以供进一步处理.
如果我想要窗口左侧的列表,垂直显示图像,我可以使用数据绑定非常优雅.
<ListBox
Name="m_listBox"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Width="60" Stretch="Uniform" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
有一种直截了当的方法,我可以使这个水平而不是垂直?解决方案的主要要求是:
ada*_*ost 116
<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>
Run Code Online (Sandbox Code Playgroud)
Bob*_*ers 19
默认ItemsPanel的ListBox控制是一个VirtualizingStackPanel,所以如果你想为控制正常,默认的经验,但只是把它水平放置,应指定这种情况(改变方向).
例:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)