Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I have an enum that I am binding to a combobox. The issue I am having is that it works in a WPF App
But not in AutoCAD
My enum...
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
public enum ApplyTo
{
[Description("Entire Drawing")]
EntireDrawing,
[Description("Current Selection")]
CurrentSelection,
}The Converter
public class EnumDescriptionTypeConverter : Autodesk.AutoCAD.DatabaseServices.EnumConverter
{
public EnumDescriptionTypeConverter(Type type)
: base(type)
{
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
if (value != null)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
if (fi != null)
{
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();
}
}
return string.Empty;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}I have tried the EnumConverter from System.ComponentModel.EnumConverter
and the xaml code
<Window.Resources>
<ObjectDataProvider x:Key="applyTo" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="dbf:ApplyTo"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources><ComboBox Name="cboApplyTo" Grid.Row="1" Grid.Column="1" Margin="3" ItemsSource="{Binding Source={StaticResource applyTo}}"/>This seems strange that it would work in the WPF app, but not AutoCAD.
Any ideas would be appreciated.
Cheers,
Brent
Solved! Go to Solution.