Hello,
I'm looking for an easy way to show a checkbox in my Xamarin Forms app. This problem seems to be a lot harder than it needs to be. The 'Switch' control built into Xamarin Forms should have been fine for us, but overriding the default TextOn & TextOff strings under Android (which are "ON" and "OFF," respectively) was unbelievably difficult. The CustomRenderer-based techniques for doing that (described in other posts on this forum) don't work for me in the latest builds of Xamarin.
I should also add that we have not taken the plunge into the XLabs library because we are still learning the base product. I felt it was a poor time to introduce a new set of UI classes before we really understand the product we paid for.
Could you please reply with your favorite checkbox solution. Or you can post any miraculous fix you have for overriding the TextOn & TextOff properties of the built-in Switch control. (Make sure it works with the Xamarin versions listed below my signature [or later ones])....
I've also provided a non-working solution below (one of the many I tried). In my opinion it is consistent with the spirit of the Xamarin guidance, but it doesn't work.
Many Thanks,
Flash
Xamarin 4.0.0.1717 (1390b70)
Xamarin.Android 6.0.0.35 (d300845)
Xamarin.iOS 9.3.99.33 (ea30b32)
Microsoft Visual Studio Enterprise 2015
Version 14.0.23107.0 D14REL
Microsoft .NET Framework
Version 4.6.00081
[assembly: ExportRenderer(typeof(CustomSwitch), typeof(CustomSwitchRenderer))]
namespace MyCo.Droid
{
public class CustomSwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
{
base.OnElementChanged(e);
Control.TextOff = "NO";
Control.TextOn = "YES";
}
}
}