cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Oskarkuus
Post Prodigy
Post Prodigy

Gallery - random background colors on each row?

I have a gallery

How can i make it so a icon or button have a random background color?

Each row/record in the gallery have a icon.

I want that icons background color (fill) to randomize color based on a set of colors i define.

 

5 REPLIES 5
ZabiBabar
Continued Contributor
Continued Contributor

Hi @Oskarkuus , there are many ways this could be done but you could add a color column to data source or your collection that is being used to display the items. The colors can be "randomized" by the values you provide. Then the button's fill can be changed by doing ThisItem.Color.

 

Best,
Zabi
Mark this post as a solution, or kudo it if you found it be helpful. You can choose more than multiple answers as solutions, including your own answer. 🙂

Anonymous
Not applicable

here is the script

 

RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1)

 

And here is an image

example_03.PNG

I hope this answers your question.

Well i have a bit of a problem changing the datasource with my app.

But i rather do the collection part.

 

My gallery is displayed from the datasource.

Can i create a collection (colColor) onStart and populate that with 20 colors in a column called color?

 

But how to use that collection in the gallery?

How to make each row in the gallery pick a random color value from the collection?

Anonymous
Not applicable

example_04.PNG

ZabiBabar
Continued Contributor
Continued Contributor

The answer @Anonymous  provided is very clever, but you would get a different color every time and you won't be able to predefine it. The only way I know how to make it predefined is to create a color collection with 2 columns - index and color. And then I would add an index column to the collection that is the source of the gallery. I did this in another post that is very similar to this. Look at both of my responses to this post. https://powerusers.microsoft.com/t5/Building-Power-Apps/Create-a-color-value-per-Distinct-values-from-a-collection/m-p/601458#M189097

 

If you want me to edit those answers and provide you a solution here you would have to provide me

  1. Source for the gallery,
  2. How many rows there,
  3. What colors you want to use,
  4. And what happens if there are more rows than colors.

 

My answer above deals with that by looping through the colors.

 

Best,
Zabi
Mark this post as a solution, or kudo it if you found it be helpful. You can choose more than multiple answers as solutions, including your own answer. 🙂

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (4,004)