protected override void OnElementChanged(ElementChangedEventArgs <Switch> e) { base.OnElementChanged(e); if (this.Control != null) { if (e.NewElement != null) { switchControl = Control as UISwitch; ctrl = (CoreSwitch)e.NewElement; trueColor = ctrl.TrueColor; falseColor = ctrl.FalseColor; switchControl.TintColor = UIColor.FromRGBA((nfloat)falseColor.R, (nfloat)falseColor.G, (nfloat)falseColor.B, 0.50f); // see example code for caveat about changing background colour... switchControl.OnTintColor = UIColor.FromRGBA((nfloat)trueColor.R, (nfloat)trueColor.G, (nfloat)trueColor.B, 0.50f); SetThumbTint(); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Switch> e) { base.OnElementChanged(e); if (this.Control != null) { ctrl = (CoreSwitch)e.NewElement; trueColor = ctrl.TrueColor; falseColor = ctrl.FalseColor; if (this.Control.Checked) { this.Control.TrackDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply); this.Control.ThumbDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply); } else { this.Control.TrackDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply); this.Control.ThumbDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply); } //this.Control.CheckedChange += this.OnCheckedChange; } }