public void TestCalcMoveRightToLeft() { var movementCalc = new ElementMovementCalculator(PositionWhenElementIsOnRightSide(), PositionWhenElementIsOnLeft(), ElementWidth()); double newLeftPosition = 0; while (movementCalc.CalculateOneMovement(-10, out newLeftPosition)) { } Assert.AreEqual(PositionWhenElementIsOnLeft(), newLeftPosition); }
private async Task MoveTo(double endPositionX, int movementSize)//, CancellationToken cancellationToken) { //tokenSource.Cancel();//cancel any existing stuff continueMoving = false; //Could try to Give the other thread time to stop //await Task.Delay(TimeSpan.FromMilliseconds(10)); continueMoving = true;//reset the flag so we can start moving double newLeftPosition = 0; var moveCalc = new ElementMovementCalculator(leftPosition: control.Margin.Left, endPositionX: endPositionX, elementWidth: control.Width); while (moveCalc.CalculateOneMovement(movementSize, out newLeftPosition)) { var newMargin = control.Margin; newMargin.Left = newLeftPosition; await Task.Delay(TimeSpan.FromMilliseconds(.5)); control.Margin = newMargin; } }