Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Scheduler > EnumToBooleanConverter can't ConvertBack to Nullable<MyEnum>

Not answered EnumToBooleanConverter can't ConvertBack to Nullable<MyEnum>

Feed from this thread
  • Brian Sayatovic avatar

    Posted on Jan 4, 2012 (permalink)

    I have a view model with a Nullable<MyEnum> property.  The EnumToBooleanConverter (from the Scheduler's assembly) appears to Convert just fine, but upon ConvertBack, a System.ArgumentException is thrown:
    • Type provided must be an Enum.
    • Parameter name: enumType
    •   at System.Enum.TryParseEnum(...)
    •   at System.Enum.Parse(...)
    •   at Telerik.Windows.Controls.EnumToBooleanConverter.ParseObjectToEnum(...) 
    •   at Telerik.Windows.Controls.EnumToBooleanConverter.ConvertBack(...) 
    • ...

    As best I can tell "targetType" is the "enumType" parameter System.Enum.TryParseEnum is complaining about.  In my case, I believe the target type for my property is Nullable<MyEnum>, which is *not* a straight Enum.

    In fact, I created my own IValueConverter that guards this and unwraps the nullable type, and then delegates to the Telerik converter

    if(targetType != null && targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable<>))
    {
        targetType = targetType.GetGenericArguments()[0];
    }

    This avoids the runtime error.
    Attached files

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Scheduler > EnumToBooleanConverter can't ConvertBack to Nullable<MyEnum>
Related resources for "EnumToBooleanConverter can't ConvertBack to Nullable<MyEnum>"

Silverlight Scheduler Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]