cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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. 🙂

Resolver I
Resolver I

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?

example_04.PNG

Continued Contributor
Continued Contributor

The answer @natmaxex  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-fro...

 

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
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (37,520)