2013-07-18 34 views
5

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

enter image description here

我试图here所示的例子。但我无法得到正确的解决方案...但我不想使用该解决方案,因为我的这是太具体。那么如何实现这一目标呢?

编辑:现在我想这一点,似乎工作...

<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(...); 
} 

现在我试图把它们放在包装面板中。现在没有运气......任何想法?

+2

那是不够的......我们不会给你你的问题,顺便说一句,我们真的不知道一个完整的解决方案。向我们展示您尝试过的内容,不能在一个小的可编译代码示例中工作,我们试图帮助您并指出您朝着正确的方向发展。 – dowhilefor

+0

问题是我不想使用该代码,因为我认为它有点具体......我需要知道改变它的通用方法。 – Sonhja

+0

具体到底是什么? WPF的美妙之处在于我知道的任何框架,这在使用和外观上很容易修改。如何从该代码开始,因为使用ListView和使用TileView是开始进行自己的调整。例如,我们在我们的应用程序中使用它,并取得了很好的结果。 – dowhilefor

回答

0

链接here驱使我找到正确的解决方案。

简单!

2

带有WrapPanel作为ItemsContainer的ItemsControl可能非常适合您正在尝试执行的操作。

+0

或多或少解决了我的问题。 :)现在我要检查如何插入图像! – Sonhja

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

尝试使用wrappanel