I’m trying to do some data binding to an enum on WPF, but I’m getting an exception.
-
First I have my NS declaration, pointing to the reference I have added to the project:
xmlns:defs="clr-namespace:API.Definitions;assembly=API"and also:
xmlns:sys="clr-namespace:System;assembly=mscorlib" -
Then I’m adding an enum to the window resources:
<Window.Resources <ResourceDictionary> <ObjectDataProvider x:Key="someEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="defs:someEnum" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </ResourceDictionary> </Window.Resources> -
I’m trying to use it on a combo box:
ComboBox ItemsSource="{Binding Source={StaticResource someEnum}}" -
Running it and getting a XamlParseException:
Type reference cannot find type named '{clr namespace:API.Definitions;assembly=API}someEnum'.
I have browsed this API reference and I can clearly see that enum and use
it on code if I’d like. I have also tested binding to a local enum (not referenced),
and this works perfectly.
Some answers implied that removing the assembly=API from xmlns:defs=”clr-namespace:API.Definitions;assembly=API” should solve this, but it doesn’t.
Thanks for your help.
Okay, I have found what was causing it — the referenced API was built for x86 rather than “Any CPU”. Any explanation for this?