I'm trying to animate the background color of a grid from black to white and back forever. However, the code below creates a flickering animation.
var contentPage = new ContentPage();
MainPage = contentPage;
var parentGrid = new Grid();
parentGrid.BackgroundColor = Color.Yellow;
contentPage.Content = parentGrid;
var grid = new Grid();
grid.VerticalOptions = new LayoutOptions
{
Alignment = LayoutAlignment.Center
};
grid.HorizontalOptions = new LayoutOptions
{
Alignment = LayoutAlignment.Center
};
grid.BackgroundColor = Color.Black;
grid.WidthRequest = 300;
grid.HeightRequest = 50;
parentGrid.Children.Add(grid);
grid.Animate(
name: "animate",
animation: new Animation((val) =>
{
grid.BackgroundColor = (grid.BackgroundColor == Color.Black) ? Color.White : Color.Black;
}),
length: 3000,
repeat: () => { return true; }
);
I'm confused as to what length
does. I assumed it was the time span the animation runs for. It's defined as uint
instead of TimeSpan
, so I'm not sure...
How can I remove the flashing effect and replace it with a natural animation from one color to another over the span of 3 seconds?