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. 🙂

natmaxex
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

ZabiBabar
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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,598)