[英]Changing the color of a Grid BackGround
在CollectionView
中,我希望GestureRecognizer
事件在用戶按下按鈕時更改背景顏色。 但是,當用戶按下另一個按鈕時,我希望前一個按鈕返回其原始顏色。
<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;
}
使用我的代碼它會改變顏色,但它永遠不能 go 回到原來的顏色
跟蹤最后選擇的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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.