6

如何ListView在 WPF 中模拟平铺视图?

在此处输入图像描述

我正在尝试此处显示的示例。但我无法找到正确的解决方案......但我不想使用该解决方案,因为它太具体了。那么如何实现呢?

编辑:我现在正在尝试这个,似乎工作......

<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>

ElementName=AdminWindow来自哪里<Window .... x:Name="AdminWindow"

我创造了我自己的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(...);
}

现在我正试图将它们放在包装面板中。现在没有运气......有什么想法吗?

4

2 回答 2

5
 <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

尝试使用包装板

于 2014-11-25T10:39:42.873 回答
2

带有 WrapPanel 作为 ItemsContainer 的 ItemsControl 可能非常适合您尝试做的事情。

于 2013-07-18T11:28:26.607 回答