Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tile view for ListView in WPf

How to simulate a tile view for a ListView in WPF?

enter image description here

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=AdminWindow comes from <Window .... x:Name="AdminWindow"

And I created my own 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?

like image 277
Sonhja Avatar asked Jul 18 '13 10:07

Sonhja


2 Answers

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

try to use a wrappanel

like image 84
juFo Avatar answered Nov 11 '22 19:11

juFo


An ItemsControl with a WrapPanel as the ItemsContainer would probably be a good fit for what you are trying to do.

like image 27
TrueEddie Avatar answered Nov 11 '22 20:11

TrueEddie