When updating context variables in a Gallery's OnSelect event is not reliable. This is reproducible in Microsoft's "With Data" template/starter app.
The screenshot below shows a simple app with a Gallery showing the contents of a Dataverse Table. This was created with the "With Data" starter template. All I did was at the three labels that show Gallery.Selected and the CurrentItem context variable. Then I clicked around a lot until the two were out of sync like in this screenshot.
I know I can use Gallery.Selected throughout the app when I need to know the current item, but sometimes I need to pre-calculate stuff when the selected item changes.
The "Text" code for those labels is just:
$"Selected={BrowseGallery1.Selected.Name} :: CurrentItem={CurrentItem.Name} :: {BrowseGallery1.Selected.Name=CurrentItem.Name}"

Report
All responses (
Answers (