Toggled event not raise for Forms Switch. Only native view switch, Toggled event only raised and Forms switch background not mapped to native view switch.
#3956 aperta il 1 ott 2018
Metriche repository
- Star
- (5644 stelle)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
Description
Our requirement is to use native view switch, to achieve this we have get the native switch using Forms Switch renderer concept. We have faced the problem in android such as Forms Switch Toggled event not raise, only native view switch Toggled event only raised and Forms switch background not mapped to native view switch.
Note: The reported scenario working fine in ios and UWP renderer , Both Forms and native switch view Toggled evet raised properly and Bakground color also working fine.
Here, we have customized a switch inside a grid in pcl. From native, we have initialized the forms switch and hooked the Toggled event and also we set the Background Color for it. The native switch is got through renderer and similarly the Toggle event hooked and background color is set for it. The toggle event and background color of native view updated but for Forms switch is not updated for Xamarin Forms Android platform. In iOS and UWP platforms it works correctly.
The android native view for Xamarin Forms switch is created through the method given in screenshot. The toggle event of forms switch is not risen in this scenario and the native switch toggle event only rises. And also the background color is not updated for forms switch when we set from renderer. But for native switch background color updates fine.
Also check the IsVisible property for switch in all the three platforms.
Steps to Reproduce
1.In the given sample 's code level ,keep the break-point in Toggled event of forms switch and in CheckedChange event of native switch in android renderer. 2.Run the sample.
Expected Behavior
The forms switch's Toggled event should rise first and then the native switch's CheckedChange event rises The background color set for forms switch updated in view. It should works similarly as like in iOS and UWP
Actual Behavior
The native switch's CheckedChange event only rises The background color for forms switch is not updated.
Basic Information
- Xamarin Forms version used: 2.4.0.280
Also tested in latest version.
- iOS: 11.2
- Android: 8.0
- Android Support Library Version: v.27.0.2.1
Screenshots

Reproduction Link
Kindly find the sample. DataForm_SwitchRenderer.zip