We want our apps to look natural and only have 1 scroll bar, we want to avoid nested scrollbars because our users hate them and find them confusing. Let’s dynamically get the height of our galleries to help our users!
Let’s dynamically calculate the height of the galleries!
NOTE: For the purposes of this discussion, I am calling Vertical/Horizontal galleries “Regular” galleries.
Row Heights
Step 1: Set the template size to a static number. Note: This will be the height of each row
Step 2: Set the height of the gallery to the following:
Self.TemplateHeight * CountRows(Self.AllItems)
Step 1: Set the template size to a static value. Note: This will be the upper limit of the row height.Â
Step 2: Add a label to the gallery. Rename the label to lblRowHeight
Step 3: Set the lblRowHeight’s Y property to the following:Â
Value(Self.Text) - Self.Height
Step 4: Set the lblRowHeight’s Text value to the height of the row. You can calculate this by getting the sum of any controls stacked vertically.Â
Â
Sum(
imgSmallImage.Y, //First Item Y Value Spacing.
Max(imgSmallImage.Height, lblTitle.Height), // Image or Title height (whichever is bigger)
// the spacing between the small image/title (whichever is bigger) and the big image.
If(imgSmallImage.Height >= lblTitle.Height,
imgBigImage.Y - (imgSmallImage.Height + imgSmallImage.Y),
imgBigImage.Y - (lblTitle.Height + lblTitle.Y)
),
imgBigImage.Height, //Height of the big image.
lblBody.Y - (imgBigImage.Height + imgBigImage.Y), // Spacing between big image and body
lblBody.Height
)
Step 5: Calculate the height of the gallery by adding together the value of the labels from each row.Â
Sum(RenameColumns(ForAll(galFlexible.AllItems, Value(lblRowHeight.Text)),"Value", "RowHeight"), RowHeight) + Self.TemplatePadding * CountRows(Self.AllItems)
All done!
Senior Power Platform Consultant ✨