7heViking
7heViking

Reputation: 7587

Create a dynamic grid depending on my data source with mvvm

Do you know if this is possible and if so how to do it?

I have a set of data which will be created at runtime in my view model. Now I want to present these data to the user in a grid which automatically creates columns and rows depending on the number of data items in my data source. When the window is created it should not generate it all over again - just let it be static as I think that is easiest.

my data source is a class containing a filepath, file name and an image.

Is it possible?

Upvotes: 0

Views: 162

Answers (1)

Sisyphe
Sisyphe

Reputation: 4659

Yes it is possible. You can use Microsoft DataGrid. It has a lot of feature that can be helpful (automatic columns generation, virtualization, columns sorting and reordering...)

Alternatively, you can use a simple ItemsControl and set its ItemsPanel as a Grid, and then implement a custom logic to generate Rows/Columns when ItemsSource changes.

Upvotes: 1

Related Questions