This is a migrated thread and some comments may be shown as answers.

Nullable Bool property converter (SegmentedEditor) not calling setter

1 Answer 175 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Developer
Top achievements
Rank 1
Developer asked on 04 May 2018, 03:49 AM

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 "";
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 08 May 2018, 08:39 AM
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
Tags
DataForm
Asked by
Developer
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or