Nullable Bool property converter (SegmentedEditor) not calling setter

2 posts, 0 answers
  1. Developer
    Developer avatar
    1 posts
    Member since:
    Jan 2018

    Posted 03 May 2018 Link to this post

    I have a nullable Boolean property in my model.
    I also have a custom property converter and custom segment control bound to the nullable Boolean.

    In my ContentPage code file I have registered the custom data source provider and the segmented editor.

    dataForm.PropertyDataSourceProvider = new NullableBoolPropertyDataSourceProvider();
    dataForm.RegisterEditor(nameof(Item.BoolToTest), EditorType.SegmentedEditor);

    Yet when I run the code and click the buttons in the segmented editor, it does not call the Boolean property setter.
    Other properties in the model work fine in that their setter gets called when they are edited on the DataForm.
    How do I get the buttons in the segmented editor to fire / call the Boolean setter?

    Below is the code.

    Public class TestModel
    {
        [DisplayOptions(Header = "Yes / No / Unknown ?")]
        [Converter(typeof(NullableBoolPropertyConverter))]
        [DataSourceKey("NullableBoolSegementedControl")]
        public bool? BoolToTest
        {
            get { return this.boolToTest; }
            set
            {
                if (value != this.boolToTest)
                {
                    this.boolToTest = value;
                    OnPropertyChanged();
                }
            }
        }
    }
     
     
    public class NullableBoolPropertyDataSourceProvider : PropertyDataSourceProvider
    {
        public override IList GetSourceForKey(object key)
        {
            switch (key.ToString())
            {
                case "NullableBoolSegementedControl":
                    return new List<string>
                        {
                            "",
                            "NO",
                            "YES"
                        };
                default:
                    return base.GetSourceForKey(key);
            }
        }
    }
     
     
    public class NullableBoolPropertyConverter : IPropertyConverter
    {
        public object Convert(object value)
        {
            if (value is bool)
                switch ((bool?)value)
                {
                    case true:
                        return "YES";
                    case false:
                        return "NO";
                    default:
                        return "";
                }
            if (value == null) return "";
            return value;
        }
     
        public object ConvertBack(object value)
        {
            if (value is string)
            {
                switch ((string)value)
                {
                    case "YES":
                        return true as bool?;
                    case "NO":
                        return false as bool?;
                    default:
                        return null as bool?;
                }
            }
                 
            switch ((bool?)value)
            {
                case true:
                    return "YES";
                case false:
                    return "NO";
                default:
                    return "";
            }
        }
    }
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1251 posts

    Posted 08 May 2018 Link to this post

    Hello,

    Thank you for providing code, describing the particular setup. I was able to reproduce the reported behavior on our side in the Android platform. I confirm this is a bug in the RadDataForm. This is why I logged it in our FeedbackPortal. You can follow the item in order to be notified whenever we update it.

    At the time of writing I was not able to find any suitable workaround that can be used.

    As a small sign of appreciation of your feedback I updated your Telerik profile.

    Regards,
    Pavel R. Pavlov
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top