I have a Combo Box that has ItemsSource Bound to an Enumeration using ObjectDataProvider, and its SelectedItem Property is bound to a property of a businessobject. For some reason it's binding SelectedItem first and ItemsSource second, therefore overwriting my default on the businessobject property. Any ideas why and possibly a fix? Thanks in Advance.
XAML:
<CollectionViewSource x:Key="Units">
<CollectionViewSource.Source>
<ObjectDataProvider MethodName="GetNames" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="BO:Unit"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</CollectionViewSource.Source>
</CollectionViewSource>
<ComboBox Grid.Column="1" HorizontalAlignment="Right" Width="80"
ItemsSource="{Binding Source={StaticResource Units}}"
SelectedItem="{Binding Path=Unit}"/>
I tried your code and it's working fine so I don't think that order of the Bindings is your problem. One thing I noticed is that you're using
GetNamesas the MethodName for theObjectDataProviderso theComboBoxItemsSource will be a Collection of strings and not of the enumUnit. If this is your intention then the PropertyUnitshould be of typestringExample
If you change
GetNamestoGetValuesit'll work for a Property of enum typeUnitExample