public void SwitchImageTick(object source, EventArgs args) { var moveTop = 0; var moveLeft = 0; var usingImageIndex = _currentBackgroundStage % 2; var otherImageIndex = usingImageIndex ^ 1; switch (_currentBackgroundStage) { case 1: moveLeft = 1; break; case 2: moveTop = 1; moveLeft = 1; break; case 3: moveTop = 1; break; default: break; } var newTop = -(moveTop * (_backgroundImages[usingImageIndex].Height - ActualHeight)); var oppositeTop = -((moveTop ^ 1) * (_backgroundImages[usingImageIndex].Height - ActualHeight)); var newLeft = -(moveLeft * (_backgroundImages[usingImageIndex].Width - ActualWidth)); var oppositeLeft = -((moveLeft ^ 1) * (_backgroundImages[usingImageIndex].Width - ActualWidth)); _backgroundImages[usingImageIndex].Source = new BitmapImage( AssetFinder.PathToUri( _lastUsedBackgroundSource = GetRandomBackgroundImageAssetPath(_lastUsedBackgroundSource))); _backgroundImages[usingImageIndex].BeginAnimation(OpacityProperty, new DoubleAnimation(0, 1.0, TimeSpan.FromSeconds(BackgroundTransitionDuration))); _backgroundImages[otherImageIndex].BeginAnimation(OpacityProperty, new DoubleAnimation(1.0, 0, TimeSpan.FromSeconds(BackgroundTransitionDuration))); StartImageMovement(_backgroundImages[usingImageIndex], newTop, oppositeTop, newLeft, oppositeLeft); _currentBackgroundStage++; if (_currentBackgroundStage == 4) { _currentBackgroundStage = 0; } }