繁体   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