user2023861
user2023861

Reputation: 8208

Why are WPF Grid.Rows zero-based, and not relative?

If I have a grid with five rows in it, the Grid.Row values are always 0, 1, 2, 3, and 4. If, during design-time, I want to insert a row after the first row, I will set its Grid.Row value to 1, but then I need to update the Grid.Row values for the four rows below the inserted row. This is annoying and error-prone.

Instead, if Grid.Row values were something like relative (I don't know the best word to describe this), I would set the Grid.Row values to 10, 20, 30, 40, and 50. In this case, if I wanted to insert a row after the first row, I would set its Grid.Row value to 15. I wouldn't need to change any other rows. The layout engine would know to put the rows in ascending order. Is there some reason that the Grid.Row values don't act this way?

HTML Z-Index values work like this

Upvotes: 3

Views: 3212

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564403

Is there some reason that the Grid.Row values don't act this way?

This would require the Grid to determine every possible row (by iterating all of it's children) during it's layout, and then placing the items. This would slow down and complicate the layout pass.

By making the grid row's explicit, this is avoided, and it helps the overall performance of the layout pass when the Grid arranges it's children.

HTML Z-Index values work like this

FYI - the Canvas class, in WPF, also uses this approach for Z indexing.

Upvotes: 8

Related Questions