Loading...

How to create your own scrollbar for galleries in Power Apps

How to create your own scrollbar for galleries in Power Apps

tl;dr

Did you know that two buttons and a slider make a sweet scrollbar? Let me show you how to do it!

curved gallery

In my last blog post about How to build a curved gallery in Power Apps I already showed how you can use a slider to scroll through a horizontal gallery, and we hid that slider. This post shall show you how you can create your own scrollbar to navigate a vertical gallery.

To make this as flexible and reuasable as possible, we will componentize this.

create a component

  1. Create a new component cmp_scrollGallery and add the following custom properties to it:

galleryStyles (Record): {X:0,Y:0,Width:cmp_scrollGallery.Width,Height:cmp_scrollGallery.Height}

galleryContent (Table):

Table({id:1,image:'image1',title:"Lake Tahoe",description:"d1"},{id:2,image:'image2',title:"Trees",description:"d2"},{id:3,image:'image3',title:"Waterfall",description:"d3"},{id:4,image:'image4',title:"Lake Louise",description:"d4"},{id:5,image:'image5',title:"Santa Barbara",description:"d5"},{id:6,image:'image6',title:"Ocean",description:"d6"},{id:7,image:'image7',title:"Beaver Dam",description:"d7"},{id:8,image:'image8',title:"Green",description:"d8."})

sizeWidth (Number): App.DesignWidth

sizeHeight (Number): App.DesignHeight

sliderStyles (Record): {X:cmp_scrollGallery.Width,Y:0,Width:50,Height:cmp_scrollGallery.Height}

backgroundBarColor (Color): ColorValue("#168aad")

scrollBarColor (Color): ColorValue("#1e6091")

scrollbarStyles (Record): {X:cmp_scrollGallery.galleryStyles.Width-20,Y:0,Width:20,Height:cmp_scrollGallery.Height}

titleStyles (Record): {Font: Font.'Open Sans', FontSize: 16, FontWeight: Bold, Color: White, Width: cmp_scrollGallery.galleryStyles.Width*0.5, Height:40, X: cmp_scrollGallery.imageStyles.X+cmp_scrollGallery.imageStyles.Width +40 } |

imageStyles (Record): {Width:128, Height: 128, BorderTopLeft: 0, BorderTopRight: Self.Width, BorderBottomLeft: 0, BorderBottomRight:0,X: 16}

bodyStyles (Record):{Font: Font.'Open Sans', FontSize: 12, FontWeight: Lighter, Color: White, Width: cmp_scrollGallery.galleryStyles.Width*0.7, Height:40, X: cmp_scrollGallery.imageStyles.X+cmp_scrollGallery.imageStyles.Width +40 }

  1. Set the Width of the component to cmp_scrollGallery.sizeWidth and the Height to cmp_scrollGallery.sizeHeight

We will now add a gallery and refer to our custom properties.

  1. Upload a few images
  2. Add a horizontal gallery gal_1
  3. Set the ShowScrollbar property to false
  4. Set its items property to cmp_scrollGallery.galleryContent
  5. X: cmp_scrollGallery.galleryStyles.X, Y: cmp_scrollGallery.galleryStyles.Y, Height: cmp_scrollGallery.galleryStyles.Height, Width: cmp_scrollGallery.galleryStyles.Width
  1. Add an image img to the gallery, set its Image property to ThisItem.image
  2. X: 16, Width: cmp_scrollGallery.imageStyles.Width, Height: cmp_scrollGallery.imageStyles.Height
  3. Add a button to the gallery, (I liked it to be semi transparent) and set its X to img.X and its Width*toimg.Width`
  4. RadiusTopRight: cmp_scrollGallery.imageStyles.BorderTopRight, all other Radius… properties shall be 0 - this creates this quarter circle effect
  5. TemplatePadding: 20, TemplateSize: 140
  1. Add a text label lbl_title
  2. X: cmp_scrollGallery.TitleStyles.X, Y: img.Y, Width: cmp_scrollGallery.TitleStyles.Width, Height: 40
  3. Color: cmp_scrollGallery.TitleStyles.Color, Font: cmp_scrollGallery.TitleStyles.Font, FontWeight: cmp_scrollGallery.TitleStyles.FontWeight, Size: cmp_scrollGallery.TitleStyles.FontSize
  4. Set its Text property to ThisItem.title
  1. Add a text label lbl_description
  2. X: cmp_scrollGallery.bodyStyles.X, Y: img.Y, Width: cmp_scrollGallery.bodyStyles.Width, Height: 40
  3. Color: cmp_scrollGallery.bodyStyles.Color, Font: cmp_scrollGallery.bodyStyles.Font, FontWeight: cmp_scrollGallery.bodyStyles.FontWeight, Size: cmp_scrollGallery.bodyStyles.FontSize
  4. Set its Text property to ThisItem.description

Now that we have the gallery, lets make it scrollable. We will add a slider control and hook this the Y property of the image. đź’ˇ The Y property of all other controls in the gallery depends on img.Y

slider

  1. Add a vertical slider sli_gal
  2. X: cmp_scrollGallery.sliderStyles.X-Self.Width, Y: cmp_scrollGallery.sliderStyles.Y, Height: cmp_scrollGallery.sliderStyles.Height, Width: cmp_scrollGallery.sliderStyles.Width
  3. Set its Min to gal_1.TemplatePadding+btn_ScrollBar.Height/2, its Max to gal_1.Height+gal_1.TemplatePadding-btn_ScrollBar.Height/2 and its Default to 50
  4. Set the HandleSize to 50
  5. Now set all color values to Transparent - we want to make the slider disappear. Don’t set the visible property to false - users can’t interact then with the control anymore

Now the most important step: Go back to img.Y and set it to sli_gal.Value-gal_1.Height+gal_1.TemplatePadding. You can now move the hidden handle and see that the items in the gallery in fact scroll :-)

Now we want to add the scroll bar:

2 buttons

Yes, for real. Our scrollbar only consists of two buttons, one for the background bar and one for the actual scroll bar

background bar

  1. Add a button btn_backgroundBar, set its DisplayMode to View, we don’t want users to interact with it.
  2. X: cmp_scrollGallery.scrollbarStyles.X, Y: 0, Height: cmp_scrollGallery.Height, Width: 20
  3. Fill: cmp_scrollGallery.backgroundBarColor

scroll bar

  1. Add a button btn_scrollBar, set its DisplayMode to View
  2. X: cmp_scrollGallery.scrollbarStyles.X, Y: sli_gal.Height-sli_gal.Value+Self.Height/2-gal_1.TemplatePadding, Height: 40, Width: 20
  3. Fill: cmp_scrollGallery.scrollBarColor

As a last step, rearrange the controls so that the slider is on top

scrollbar and gallery

Feedback and what’s next?

Who would have thought that its that easy to create your own custom scrollbar? Adjust sizes and colors as you please, and let me know on twitter how you like it! If you found this blog post useful, please also subscribe to my newsletter - news coming about every 2 months, I promise to not spam you!

Published on:

Learn more
Need help with this product?

We can help you with How to create your own scrollbar for galleries in Power Apps

If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.

Luise Freese: Consultant & MVP
Luise Freese: Consultant & MVP

Recent content on Luise Freese: Consultant & MVP

Share post:

Related posts

You are holding GitHub Copilot Wrong!

Most developers think that one can’t really use GitHub Copilot wrong. There is a chat interface that lets you also choose a model, so th...

8 months ago

You are holding GitHub Copilot Wrong!

Part 0 showed why constant prompting, re-prompting, and steering GitHub Copilot feels fragile. Not because Copilot is unreliable, but because ...

8 months ago

Building a Multi-Hierarchy Ticket Classification System (Because Keywords Aren't Enough)

Look, I love a good keyword-based system as much as the next developer. They’re fast, predictable, and when your user says “VPN,&r...

8 months ago

Secretless cross-tenant dataverse access

Client secrets are like hiding your house key under the mat; easy to grab and impossible to audit. Certificates are just slightly better, beca...

10 months ago

How Azure CLI handles your tokens and what you might be ignoring

Running az login feels like magic. A browser pops up, you pick an account, and from then on, everything just works. No more passwords, no more...

10 months ago

How Dev Proxy teaches you to make your apps more resilient

I added Microsoft Dev Proxy to my Mermaid → Dataverse converter, because I wanted to test how it handled rate limits and API errors. What I go...

10 months ago

Building Azure functions that never store secrets — ever

What if your function could hit Microsoft Graph with no client secrets, no certs, and no Key Vault entries? That is exactly what a Managed id...

11 months ago

Introducing Mermaid to Dataverse Converter

Why diagrams matter (and why they usually fail us) Entity-Relationship Diagrams (ERDs) are the universal shorthand for talking about data mode...

11 months ago

It’s OK to be seen trying

It’s OK to be seen trying Somewhere along the way, we started believing that you’re only allowed to speak after you’ve figured everything out....

1 year ago

Stuck in pilot - Part 1: no foundations, no future

“We just need to test the AI. We’ll figure out the data later.” That sentence has quietly killed more AI pilots than any model failure ever ...

1 year ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.