WPf 中 ListView 的平铺视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17721279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tile view for ListView in WPf
提问by Sonhja
How to simulate a tile view for a ListViewin WPF?
如何模拟ListViewWPF 中的平铺视图?


I was trying the example shown here. But I can't get to the right solution... But I don't want to use that solution as I it's too much specific. So how will be the way to accomplilsh that?
我正在尝试此处显示的示例。但我无法找到正确的解决方案......但我不想使用该解决方案,因为它太具体了。那么如何实现呢?
EDIT:I'm trying this now and seems to work...
编辑:我现在正在尝试这个并且似乎工作......
<ListBox ItemsSource="{Binding Path=ListObservableUsers, ElementName=AdminWindow}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Image Source="{Binding Path=Picture}"></Image>
<Label Content="{Binding Path=Dni}"></Label>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Where the ElementName=AdminWindowcomes from <Window .... x:Name="AdminWindow"
ElementName=AdminWindow来自哪里<Window .... x:Name="AdminWindow"
And I created my own ObservableCollection<MyUser>
我创造了我自己的 ObservableCollection<MyUser>
public class MyUser
{
public MyUser(int id, string dni, Bitmap picture)
{
Id = id;
Dni = dni;
Image img = new Image();
FPhiMultipleSources.FromBitmapImage(img, picture);
Picture = img.Source;
}
public int Id { get; set; }
public string Dni { get; set; }
public ImageSource Picture { get; set; }
}
...
public UCAdminMain()
public UCAdminMain()
{
ListObservableUsers = new ObservableCollection<MyUser>();
InitializeComponent();
uiCurrent = SynchronizationContext.Current;
// Create users to add with its image
....
ListObservableUsers.Add(...);
}
And now I'm trying to put them inside a wrap panel. With no luck right now... Any ideas?
现在我试图把它们放在一个包裹面板里。现在没有运气......有什么想法吗?
回答by juFo
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
try to use a wrappanel
尝试使用包装面板
回答by TrueEddie
An ItemsControl with a WrapPanel as the ItemsContainer would probably be a good fit for what you are trying to do.
带有 WrapPanel 作为 ItemsContainer 的 ItemsControl 可能非常适合您要执行的操作。

