How can I stop the clicking on a ViewCell from changing the background color for a brief time?

Viewed 3772

I have this XAML code:

<TableView x:Name="tableView" Intent="Settings" HasUnevenRows="True">
   <TableSection>
      <TableSection.Title>
         Card Selection
      </TableSection.Title>
      <ViewCell Height="50">
         <Grid>
            <Grid x:Name="deselectGridLink" VerticalOptions="CenterAndExpand" Padding="20, 0">
               <Label TextColor="Blue" Style="{DynamicResource ListItemTextStyle}" x:Name="deselectLink" HorizontalOptions="StartAndExpand" VerticalOptions="Center" Text="Deselect All" />
            </Grid>
            <Grid x:Name="deselectGridLabel" VerticalOptions="CenterAndExpand" Padding="20, 0">
               <Label TextColor="Silver" Style="{DynamicResource ListItemTextStyle}" x:Name="deselectLabel" HorizontalOptions="StartAndExpand" VerticalOptions="Center" Text="Deselect All" />
            </Grid>
         </Grid>
       </ViewCell>
       <ViewCell Height="50">
          <Grid x:Name="selectGridLink" VerticalOptions="CenterAndExpand" Padding="20, 0">
             <Label TextColor="Blue" Style="{DynamicResource ListItemTextStyle}" x:Name="selectLink" HorizontalOptions="StartAndExpand" VerticalOptions="Center" Text="Select All" />
           </Grid>
        </ViewCell>
   </TableSection>
</TableView>

When other parts of my code call: SetPageDetails() then the label in the grid is changed to a link or the link is changed to a label. So for this when it is a label I would like to have no background flash event and no action called.

I attach a tap gesture recognizer like this. Note it's all on one line but covers two lines so it's more visible here in the SO question:

deselectGridLink.GestureRecognizers
      .Add(NewTapGestureForUpdateCategories(false));

    private TapGestureRecognizer NewTapGestureForUpdateCategories(bool val)
    {
        return new TapGestureRecognizer()
        {
            Command = new Command(() =>
            {
                App.DB.UpdateAllCategoryGroups(val);
                App.DB.UpdateAllCategories(val);
                GetPageData();
                RemoveTableViewClickSection();
                tableView.Root.Add(CreateTableSection());
            })
        };
    }

When the user clicks the row when deselectGridLink grid is visible then:

  • The deselectGridLink visibility is set to false
  • The deselectGridLabel visibility is set to true

    private void SetPageDetails()
    {
        Title = App.cardCountForSelectedCategories + (App.cardCountForSelectedCategories == 1 ? " Card Selected" : " Cards Selected");
        if (App.cardCountForSelectedCategories == 0)
        {
            deselectGridLink.IsVisible = false;
            deselectGridLabel.IsVisible = true;
        }
        else
        {
            deselectGridLink.IsVisible = true;
            deselectGridLabel.IsVisible = false;
        }
    }
    

The effect of this is that the grid link text will change to silver and the link becomes a label.

However even though it's a gray color label when the label is clicked there is still a brief background row color change from white to a dark color when the label is clicked. I assume it's just the way a view cell works.

Is there a way to suppress this from happening?

2 Answers

What G.Sharada proposes is very nicely working for iOS, but on Android I still had blinks on click. Adding this line to the styles file solved the problem.

<item name="android:colorActivatedHighlight">@android:color/transparent</item>
Related