2013-07-18 30 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