Странно, на мой взгляд, Xaml не может анализировать все типы, которые реализуют IConvertible
. (Хотелось бы узнать причину, если кто-нибудь из вас скрывается от магии, желает назидать?)
Вот реализация, которая может помочь: -
public class ConvertibleTypeConverter<T> : TypeConverter where T: IConvertible
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType.GetInterface("IConvertible", false) != null;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType.GetInterface("IConvertible", false) != null;
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return ((IConvertible)value).ToType(typeof(T), culture);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return ((IConvertible)value).ToType(destinationType, culture);
}
}
Теперь в свойстве MaxLongNumericValue
вы используете такой атрибут: -
[TypeConverter(typeof(ConvertibleTypeConverter<long>))]
public long MaxLongNumericValue { get; set; }
Теперь, когда парсер Xaml получит это свойство, он будет отложен до указанного TypeConverter
.