Xamarin forms: Getting NotImplementedException

1.2k Views Asked by At

I have a switch in my listview. In xaml, a converter added for the IsToggled property:

<Switch
          IsToggled="{Binding userProfileTO.userId, Converter={StaticResource isToggledConverter}}"
          HorizontalOptions="EndAndExpand"
          VerticalOptions="CenterAndExpand"/>

Converter code:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    bool toggle = false;
    // My Codes
    return toggle;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
    throw new NotImplementedException();
}

Getting an NotImplementedException on ConvertBack when running this code.

Exception thrown: 'System.NotImplementedException' in Myprojectname.dll
An exception of type 'System.NotImplementedException' occurred in Myprojectname.dll but was not handled in user code
The method or operation is not implemented.
1

There are 1 best solutions below

3
On BEST ANSWER

The default binding type of IsToggled property is "Two-way". That's why your ConvertBack function is getting called. You can simply remove the

throw new NotImplementedException();

in your ConvertBack method and everything will work fine.

Or if you don't wanna do that you can explicitly set the binding mode to be One-way