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

DataForm with enum filed throws exception on Android.

2 Answers 63 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 12 Jul 2017, 04:00 PM

I need to have a language select drop down on a data form so I used a language enum as one of the properties on the view model. The drop-down works fine on UWP but throws an exception when rendering on Android. It works fine on Android if I change the field type to string instead of enum. Here is the view model:

public class AppConfiguration
    {
    [DisplayOptions(Header = "API URL")]
    public string ApiUrl { get; set; }
 
    [DisplayOptions(Header = "Preferred Culture")]
    [Ignore]
    public string Culture { get; set; }
 
    public enum LanguageChoices { English, French };
 
    //[DisplayOptions(Header = "Preferred Language")]
    //public string LanguageChoice
    //  {
    //  get
    //      {
    //      if(string.IsNullOrEmpty(Culture))
    //          Culture="en-CA";
    //      switch(Culture.Substring(0, 2).ToLower())
    //          {
    //      case "en":
    //          return "English";
    //      case "fr":
    //          return "French";
    //      default:
    //          return "English";
    //          }
    //      }
    //  set
    //      {
    //      switch(value.Substring(0, 2).ToLower())
    //          {
    //      case "fr":
    //          Culture="fr-CA";
    //          break;
    //      case "en":
    //          Culture="en-CA";
    //          break;
    //      default:
    //          Culture="en-CA";
    //          break;
    //          }
    //      }
    //  }
 
    [DisplayOptions(Header = "Preferred Language")]
    public LanguageChoices LanguageChoice
        {
        get
            {
            if(string.IsNullOrEmpty(Culture))
                Culture="en-CA";
            switch(Culture.Substring(0, 2).ToLower())
                {
            case "en":
                return LanguageChoices.English;
            case "fr":
                return LanguageChoices.French;
            default:
                return LanguageChoices.English;
                }
            }
        set
            {
            switch(value)
                {
            case LanguageChoices.French:
                Culture="fr-CA";
                break;
            case LanguageChoices.English:
                Culture="en-CA";
                break;
            default:
                Culture="en-CA";
                break;
                }
            }
        }
    }

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 13 Jul 2017, 01:41 PM

Just to make sure that there was nothing else in my program aggravating the issue, I was able to reproduce the problem in the Telerik SDKBrowswer sample simply by adding the following lines to SourceItem.cs in the DataForms sample:

public enum LanguageChoices { English, French };
 
[DisplayOptions(Header = "Language")]
public LanguageChoices Language { get; set; }
0
Accepted
Stefan Nenchev
Telerik team
answered on 17 Jul 2017, 08:25 AM
Hello John,

As my colleague has advised in the ticket you have raised - enumerations are not supported by the default editors. With this in mind, you can use a PickerEditor or a SegmentedEditor in order to edit such properties. Please have a look at the "Editors" example in our SDK Samples Browser where a Segmented editor is used for the "TargetGroup" property of the book object.

Regards,
Stefan Nenchev
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
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Stefan Nenchev
Telerik team
Share this question
or