To be able to calculate the state, we need to clamp a value later on. At the time of writing, this function is already in Xamarin.Forms, but it's marked as an internal function, meaning that we shouldn't really be using it. According to the rumors, it will soon be made public in later versions of Xamarin.Forms, but for now, we need to redefine it ourselves, as follows:
- Open SwiperControl.xaml.cs.
- Add the following static method to the class:
private static double Clamp(double value, double min, double max)
{
return (value < min) ? min : (value > max) ? max : value;
}
The method takes a value to clamp, a minimum boundary, and a maximum boundary. It returns either the value itself or the edge value if it's greater or larger than the set boundaries.