We want a simple function that determines if an image has panned far enough for it to count as an exit of that image. To create such a function, proceed as follows:
- Open Controls/SwiperControl.xaml.cs.
- Add the CheckForExitCriteria() method to the class, as shown in the following code snippet:
private bool CheckForExitCriteria()
{
var halfScreenWidth = _screenWidth / 2;
var decisionBreakpoint = DeadZone * halfScreenWidth;
return (Math.Abs(photo.TranslationX) > decisionBreakpoint);
}
This function calculates whether we have passed over the dead zone and into the decision zone. We need to use the Math.Abs() method to get the total absolute value to compare it against. We could have used a < and a > operator as well, but we are using this approach as it is more readable. This is a matter of code style and taste—feel free to do it your own way.