In the CollectionView
I would like the GestureRecognizer
event to change the background color when the user presses a button. However, when the user presses on yet another button, I would like the previous one to return to its original color.
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="12"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="SelectedDate_Tapped"/>
</Grid.GestureRecognizers>
<Label Grid.Row="0" HorizontalTextAlignment="Center" Text="{Binding Giorno}" TextColor="White" FontSize="10"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
private void SelectedDate_Tapped(object sender, EventArgs e)
{
var model = (Grid)sender;
model.BackgroundColor = Color.Blue;
}
With my code it changes color, but it can never go back to the original color
track the last selected Grid
Grid last = null;
private void SelectedDate_Tapped(object sender, EventArgs e)
{
var model = (Grid)sender;
model.BackgroundColor = Color.Blue;
if (last != null) last.BackgroundColor = myDefaultColor;
last = model;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.