簡體   English   中英

更改網格背景的顏色

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM