0

我的列表视图中有一个开关。在 xaml 中,为 IsToggled 属性添加了一个转换器:

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

转换器代码:

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();
}

运行此代码时在 ConvertBack 上获得 NotImplementedException。

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.
4

1 回答 1

3

属性的默认绑定类型IsToggled是“ Two-way”。这就是你的ConvertBack函数被调用的原因。您可以简单地删除

throw new NotImplementedException();

在您的ConvertBack方法中,一切都会正常工作。

或者,如果您不想这样做,您可以将绑定模式显式设置为One-way

于 2018-10-01T13:35:05.933 回答