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.
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. 🙂
here is the script
RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1)
And here is an image
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?
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
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. 🙂
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
185 | |
51 | |
47 | |
32 | |
32 |
User | Count |
---|---|
258 | |
89 | |
78 | |
67 | |
67 |