Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How do you dynamically make individual Grid rows size themselves to their children?

$
0
0

I have a grid that fills itself up from data/calculations stored in a database. Because of this, the database may change and all rows need to be dynamic (no XAML setting individual RowDefinitions).

What appears to be the behavior is that, if a string reaches the end of the width of the Grid the label wraps. That's fine and what I want.

But instead of just that one row taking up two rows of space, every single row is taking up twice as much space. It seems that a Row does not default its height to it's children in my grid, but instead it defaults to the biggest child in every single row.

I believe this has to do with RowDefinitions either defaulting to GridLength type * or GridLength type Auto.

My question is, how do I change this behavior so each row takes on the height of that rows children, NOT the height of the biggest child in the entire grid.

How I currently am filling them all is I cycle through my Row objects (that hold the data of every row) and foreach RowObject increase the rows index by 1 when adding children to the grid (and foreach item in row object increase the column count by 1), successfully filling in the grid as I wanted. The downside is that I am not setting RowDefinitions for each item, so Grid is relying on it's default definitions.

Is there a way to change it's default behaviour? Or do I basically need to make a row definition for each and every single row that gets created and set its personal GridLength?

Image showing the case of what I mean. Both rows are larger then wanted despite only one needing the extra space.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>