To access a nested type, you should use the "+" separator :
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="ContactExportTypes">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:Enums+ContactExportType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
By the way, there is a simpler way to bind to the values of an enum, without using an ObjectDataProvider. It's based on a custom markup extension :
<ComboBox ItemsSource="{local:EnumValues local:Enums+ContactExportType}"/>
Here is the code for the EnumValues markup extension :
[MarkupExtensionReturnType(typeof(object[]))]
public class EnumValuesExtension : MarkupExtension
{
public EnumValuesExtension()
{
}
public EnumValuesExtension(Type enumType)
{
this.EnumType = enumType;
}
[ConstructorArgument("enumType")]
public Type EnumType { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (this.EnumType == null)
throw new ArgumentException("The enum type is not set");
return Enum.GetValues(this.EnumType);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…