Auto Binding to object with nullable enums

7 posts, 0 answers
  1. Oscar Ågren
    Oscar Ågren avatar
    5 posts
    Member since:
    Aug 2012

    Posted 08 Aug 2012 Link to this post

    Hi,

    I cant bind to an object with nullable enums using auto generated properties.
    I get a silent error for every nullable enum property
    System.Windows.Data Error: 1 : Cannot create default converter to perform 'two-way' conversions between types 'System.Nullable`1[Data.EF5.Enumerations.Unit]' and 'System.String'. Consider using Converter property of Binding. BindingExpression:Path=Unit1; DataItem='Mb' (HashCode=13923471); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')


    Part of the enum looks like this (localized)

    [TypeConverter(typeof(EnumToLocalizedName))]
       public enum Unit:int
       {
           [Display(Description = " ", ResourceType = typeof(Resources.Resource))]
           Unit0,
           [Display(Description = "°C", ResourceType = typeof(Resources.Resource))]
           Unit1
       ....
    }

    Non-nullable enums shows up in a combobox. How can I show my nullable enums the same way, without losing localization?

    Thanks
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 13 Aug 2012 Link to this post

    Hi,

    Currently nullable enums are not supported by RadPropertyGrid in scenarios with auto-generated fields. We will do our best to add this feature in some of our future internal builds. I will write to you, in order to notify you as soon as the mentioned version is available. 

    All the best,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Oscar Ågren
    Oscar Ågren avatar
    5 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    Okey, thanks for clarifying. I was able to work around the nullable requirement. 

    Still one problem remaining. How can I localize the enum names for the combobox? My typeconverter attribute is ignored. What attributes does the PropertyGrid require? Thanks
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 16 Aug 2012 Link to this post

    Hi,

     We will need some more time, in order to check this. I will contact you tomorrow, in order to notify you of the results of our research. Please, excuse me for this delay.

    Regards,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 20 Aug 2012 Link to this post

    Hi,

    We have tested this scenario on our side and it appears that currently there is no easy workaround for this scenario. Would it be possible for you to use a non-nullable enum property and add a value that would mimic the null value, in the enum definition? The internal build that introduces support for Nullable enums will be released later today/tomorrow, but unfortunately the TypeConverter is not yet working properly with it.

    All the best,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Oscar Ågren
    Oscar Ågren avatar
    5 posts
    Member since:
    Aug 2012

    Posted 20 Aug 2012 Link to this post

    I have removed all nullable enums, it wasn't that big a loss, all I want now is to get localization for my non nullable enums. What would be the practiced pattern? Thanks
  8. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 24 Aug 2012 Link to this post

    Hi,

    It seems that the EnumDataSource that we internally use in RadPropertyGrid fails to invoke the TypeConverter properly. We will need some more time to investigate this. I will contact you as soon as we have any updates.

    All the best,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready