Skip to content

Instantly share code, notes, and snippets.

@colinkiama
Last active February 27, 2018 15:27
Show Gist options
  • Save colinkiama/659bf5f135436512c90745b1835b0a15 to your computer and use it in GitHub Desktop.
Save colinkiama/659bf5f135436512c90745b1835b0a15 to your computer and use it in GitHub Desktop.
Use Community Toolkit to animate a FontIcon continuously. Speed can be adjusted.
private async Task animateSyncingIcon()
{
nowSyncing = true;
var centerX = (float)syncIcon.ActualWidth / 2;
var centerY = (float)syncIcon.ActualHeight / 2;
const int maxRotation = 360;
double rotationsToPerform = 10;
double rotationsPerSecond = (double)(1 / rotationsToPerform);
var duration = (float)(rotationsPerSecond / maxRotation);
int rotation = 1;
while (nowSyncing)
{
if (rotation == maxRotation)
{
await syncIcon.Rotate(0, centerX, centerY, 0).StartAsync();
rotation = 0;
}
await syncIcon.Rotate(rotation, centerX, centerY, duration).StartAsync();
rotation += (int)rotationsToPerform;
}
Fioe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment