web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Conditional Color of I...
Power Apps
Answered

Conditional Color of Icon in Gallery

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all, 

 

In my application I currently have a gallery consisting of many items, of which each item has a blue bookmark icon. Upon clicking a specific item's bookmark, I would like the bookmark's color to become red, and stay red. 

 

I know you can change the color of the icon using: If(ThisItem.IsSelected, Red, Blue); however, upon clicking a different bookmark, any previously clicked bookmarks will return back to the default blue color. 

 

Once clicked, I would like those bookmarks to stay red regardless of clicking on more icons. Please let me know if you have any ideas. Thank you very much. 

Categories:
  • Verified answer
    yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @Anonymous 

     

    For doing so, you can create a local collection to store the selected items and use this collection to set the icon color.
     
    Expressions:
     
    Screen -> OnVisible: Clear(SelectedGalleryItems)
     
    Gallery -> OnSelect: Collect(SelectedGalleryItems,ThisItem.Id) #Id need to be replaced with a uniquely identified column.
     
    Gallery -> Icon FIll -> If(ThisItem.Id in Selected.Value,Red,White)MicrosoftTeams-image (179).png

     

     
    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you very much @yashag2255 , that worked perfectly. However, upon clicking an icon that is already red/in the collection, I would like the color to change back to blue and the icon be removed from the collection.

     

    For the icon's On Select property, I tried: 

    Note: the name of my collection is pinnedEventsColor 

     

    If(ThisItem.SampleHeading in pinnedEventsColor.Value, Remove(pinnedEventsColor, ThisItem.SampleHeading), Collect(pinnedEventsColor, ThisItem.SampleHeading));

     

    However, this of course is giving an error for the remove portion of this function. Any better ideas? 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Just kidding I figured it out, I needed to have value in the remove function as such: Remove(pinnedEventsColor, {Value: ThisItem.SampleHeading}). Thank you very much 

  • K-A-R-L Profile Picture
    715 on at

    Hi @Anonymous ,

     

    Just another suggestion:
    I assume you want also your favorite to be saved or write back to the data source?

     

    On your gallery's bookmark icon OnSelect() Property add this:

    If(ThisItem.ID exactin favorites.ID,
    	Remove(favorites,ThisItem),
    	Collect(favorites,ThisItem)
    );
    
     Patch(
     AttachmentTest,
     First(
     Filter(
     AttachmentTest,
     ID = ThisItem.ID
     )
     ),
     {
     Favorite: If(
     ThisItem.Favorite = "Yes",
     "No",
     "Yes"
     )
     }
    );

    On Fill() Property:

    If(
     ThisItem.Favorite = "Yes",
     RGBA(186, 202, 226, 1),
     
     RGBA(
     255,
     255,
     255,
     1
     
     )
    )

    On BorderStyle() Property: (Change Border Thickness to 1)

    If( ThisItem.Favorite = "Yes",
    	None,
    	Solid
    )

    Please see images below:
    ss1.jpg

    ss2.jpg

    You can tick and untick the icons to remove from the collection and from the DataSource.

    ----------------------------------------------------------------------------
    Thanks,
    K-A-R-L


    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    If you thought this post was helpful, please give it a Thumbs Up.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard