We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem using Converter with DataForm

I have a string field called Withholdingtaxes with 2 possible value "S" and "N".

I do use this converter to make it bool :
[Converter(typeof(SNBooleanConverterExt))]
public string Withholdingtaxes { get; set; }

 public class SNBooleanConverterExt : IPropertyValueConverter
    {
        public object Convert(object value)
        {
            return (bool)(value.ToString().Equals("S"));
        }

        public object ConvertBack(object value)
        {
            return (bool)value ? "S" : "N";
        }
    }


I want to show it as a "Switch" :
dataForm.RegisterEditor("Withholdingtaxes", "Switch");

My DataForm is by default ReadOnly. And It seems to be working as expected.

But, when I click on the Edit Button, I call this code :

dataForm.IsReadOnly = false;
dataForm.RefreshLayout();

And now I got this error :
System.InvalidCastException: 'Unable to cast object of type 'System.String' to type 'System.Boolean'.'

It seems to be ignoring the converter when I call RefreshLayout();

How can I fix this?




4 Replies

DY Deivaselvan Y Syncfusion Team March 14, 2019 12:26 PM UTC

Hi Cezar, 
 
Thank you for contacting Syncfusion support. 
 
Currently, we are analyzing the reported behavior “InvalidCastException throws while using converter to convert from string to bool for SwitchEditor” in source and sample level, we will update you for this in two business days on 18th March 2019. We appreciate your patience until then. 
 
Regards,
Deivaselvan 



DY Deivaselvan Y Syncfusion Team March 18, 2019 12:19 PM UTC

Hi Cezar, 
 
Thank you for your patience. 

We can reproduce the reported issue “InvalidCastException throws while using converter to convert from string to bool for SwitchEditor”. Currently, we are validating the issue in both source and sample level, and we will update the details for the same in two business days on 20th March 2019. We appreciate your patience until then. 

Regards,
Deivaselvan 



DY Deivaselvan Y Syncfusion Team March 20, 2019 12:21 PM UTC

Hi Cezar, 
 
Thank you for your patience. 
 
We can reproduce the reported issue “InvalidCastException throws while using converter to convert from string to bool for SwitchEditor” and we have logged an issue report for the same, we will update you with patch for this issue fix on or before 27th March 2019. We appreciate your patience until then. Now You can now track the status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link. 
 
 
Kindly revert us if you have any other questions. 
 
Regards, 
Deivaselvan 



DY Deivaselvan Y Syncfusion Team March 27, 2019 11:16 AM UTC

Hi Cezar, 
 
Thank you for your patience. 
 
We have fixed the mentioned issue “InvalidCastException throws while using converter to convert from string to bool for SwitchEditor” and the patch for the issue fix is following by. 
 
Set Up: 
 
Custom Assemblies: 
 
Nuget: 
 
Kindly find the below link to clear Nuget cache,
https://www.syncfusion.com/kb/6987/how-to-clear-nuget-cache    
    
Installation Direction:       
{Syncfusion Installed location}\Essential Studio\16.4.0.52\Xamarin\lib\pcl\Syncfusion.SfDataForm.XForms.dll             
{Syncfusion Installed location}\Essential Studio\16.4.0.52\Xamarin\lib\android\Syncfusion.SfDataForm.XForms.Android.dll             
{Syncfusion Installed location}\Essential Studio\16.4.0.52\Xamarin\lib\android\Syncfusion.SfDataForm.XForms.iOS.dll             
{Syncfusion Installed location}\Essential Studio\16.4.0.52\Xamarin\lib\android\Syncfusion.SfDataForm.XForms.UWP.dll            
     
     
Disclaimer:     
Please note that we have created this patch for version 16.4.0.52 specifically to include the issue reported in Forum 143316, we will include this fix in our upcoming Volume 1 main release, which is expected to roll out at the end of March 2019. 
    
Please let us know if you need further assistance.    
 
Regards,    
Deivaselvan 


Loader.
Live Chat Icon For mobile
Up arrow icon