Asperger
Asperger

Reputation: 3222

Binding column / row definitions to a Grid in WPF (Dynamic grid)

If I want to dynamically create a Grid with Row and Column Definitions then what would be the proper way to do so? This is probably the hardest thing for me as im not sure where to start. I know I can do this in code behind but that would be against the mvvm principles?

So my question is how can I add or bind the row / column definitions?

<Grid>
    <ColumnDefinitions>
        // Bind definitions here
    </ColumnDefinitions>

    <RowDefinitions>
        // Bind definitions here
    </RowDefinitions>
</Grid>

I cant use a uniform or datagrid grid since I have to use the normal grid due to some design decitions.

Upvotes: 1

Views: 1675

Answers (1)

mm8
mm8

Reputation: 169150

I know I can do this in code behind but that would be against the mvvm principles?

No, it wouldn't. ColumnDefinitions and RowDefinitions are things that belong to the view. A view model shouldn't have any knowledge of these kind of things/elements/types.

And there is no way to bind to the Grid.ColumnDefinitions or Grid.RowDefinitions properties to some source collections.

Upvotes: -1

Related Questions