Xamarin Forms - Check a switch has been toggled manually

Viewed 3417

I am writing a Xamarin forms application which checks whether or not a user is in a specific geo-location. When a user walks inside an area, a XAML switch is toggled from the off to on position.

farmSwitch.toggled = true;

This calls this function

farmSwitch.Toggled += (object sender, ToggledEventArgs e) => {
            manualOnFarm = true;
            Console.WriteLine("Switch.Toggled event sent");
            changeOnFarmStatus(e);
        };

I also need functionality where a user manually clicks the switch, which need to be differentiated from when the code automatically toggles farmSwitch

The reason is that I have a boolean that should only be true when the user manually clicks farmSwitch, and should be false when the switch is toggled automatically

What are my options? Ideally there would be a farSwtich.clicked() function I could call for when a user manually clicks farmSwitch, but no such luck

2 Answers
Related