cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
andrewichert
Level 8

Count elements in gallery / full gallery height in canvas

Hello,

 

I've created a gallery inside a canvas element. Each gallery element contains several elements to display. I want to calculate the sum of the height of all gallery items to set the number for the Height-Attribute of the gallery.

 

The gallery should be shown with full height and I want to use this inside a gallery element to add other items below the gallery.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Mike8
Level 10

Re: Count elements in gallery / full gallery height in canvas

Hello andrewichert,

You can add a label in your MyGallery. Let's name it LabelRecordSum.

Please set:
LabelRecordSum.Text= Label1.Height+Label2.Height+Label3.Height+Label4.Height
This label will show the sum of the labels' heights 

Now outside of your gallery create a label ---> LabelSum
LabelSum.Text=Sum(MyGallery.AllItems,LabelRecordSum.Text)

Now you can set:
LabelRecordSum.Visible=false and it's hidden from the user but still does what you need.

I hope it's good enough for you.

14 REPLIES 14
Super User
Super User

Re: Count elements in gallery / full gallery height in canvas

Each control has an X value and Y value. So you can sum the total of the controls Y values to set your size. 

 

If you add a control to the page you will see that data cards are done this way automatically. This would give you a working example.

 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
andrewichert
Level 8

Re: Count elements in gallery / full gallery height in canvas

Hi @Shanescows,

 

thank you for your reply. I'm aware of the X and Y property but do not know how to sum all items of the gallery.

 

In my case it will look something like this:

Gallery

- Item1

  - label 1 (Height 10)

  - label 2 (Height 10)

- Item2

  - label 3 (Height 20)

  - label 4 (Height 20)

 

So the sum has to be 60 for the gallery.

Super User
Super User

Re: Count elements in gallery / full gallery height in canvas

Why are the heights different for Item 1 vs. Item 2? 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
andrewichert
Level 8

Re: Count elements in gallery / full gallery height in canvas

These elements are "HTML text" controls and their height depends on the content. If the elements where all the same height, I would just Count the rows and multiply by a value. This is the problem I ran into.

Super User
Super User

Re: Count elements in gallery / full gallery height in canvas

What is your data source? I wonder if you put it into a collection first you could use ForAll or Count to do the calculations.

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
andrewichert
Level 8

Re: Count elements in gallery / full gallery height in canvas

My source is a collection of a Sharepoint list. I've already found ForAll but couldn't figure out how to sum all elements.

Super User
Super User

Re: Count elements in gallery / full gallery height in canvas

It is a tricky function. What have you tried that doesn't work? 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
andrewichert
Level 8

Re: Count elements in gallery / full gallery height in canvas

I've tried something like this: ForAll( MyGallery.AllItems, predefinedVar + This.Height). So basically I thought I can add each item height to a given variable.

andrewichert
Level 8

Re: Count elements in gallery / full gallery height in canvas

I wonder if it's even possible to access all elements (like labels) of a gallery and sum the height.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 226 members 5,366 guests
Please welcome our newest community members: