locked
On the listview switch based on a condition,tried a method but getting NotImplementedException? RRS feed

  • Question

  • User351573 posted

    I have a switch in my listview. I need to on the switch state if the switch item userid exists in the local DB. I tried like below:

    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;
            string selectedIds = Application.Current.Properties["GroupUserIds"].ToString();
            if (!string.IsNullOrWhiteSpace(selectedIds))
            {
                List<int> TagIds = selectedIds.Split(',').Select(int.Parse).ToList();
                if (TagIds.Contains(Int32.Parse(value.ToString())))
                {
                    toggle = true;
                }
                else
                {
                    toggle = false;
                }
            }
            return toggle;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    

    But I am getting an exception 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.
    

    Thanks in advance :)

    Monday, October 1, 2018 11:33 AM

Answers

  • User351573 posted

    Hi @ManojkumarMali :) The default binding type of IsToggled property is "Two-way". That's why my ConvertBack function is getting called. If I remove the throw new NotImplementedException(); in my ConvertBack method and everything will work fine. Or explicitly set the binding mode to be One-way.

    But this fix doesn't solve my real problem. :) My real problem is need to on the switch state if the switch item userid exists in the local DB.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, October 2, 2018 3:34 AM

All replies

  • User261729 posted

    Hi,

    Have you marked your converter as local resource on page under page resources?

    Monday, October 1, 2018 12:18 PM
  • User351573 posted

    Hi @ManojkumarMali :) The default binding type of IsToggled property is "Two-way". That's why my ConvertBack function is getting called. If I remove the throw new NotImplementedException(); in my ConvertBack method and everything will work fine. Or explicitly set the binding mode to be One-way.

    But this fix doesn't solve my real problem. :) My real problem is need to on the switch state if the switch item userid exists in the local DB.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, October 2, 2018 3:34 AM
  • User351573 posted

    @Sreeee said: Hi @ManojkumarMali :) The default binding type of IsToggled property is "Two-way". That's why my ConvertBack function is getting called. If I remove the throw new NotImplementedException(); in my ConvertBack method and everything will work fine. Or explicitly set the binding mode to be One-way.

    But this fix doesn't solve my real problem. :) My real problem is need to on the switch state if the switch item userid exists in the local DB.

    Added more details here

    Tuesday, October 2, 2018 7:47 AM