I have a combobox, which is filled with enums via data binding and this works quite well. Also the binding of the selected item to a property works fine.
I have set the binding to the property to TwoWay, but if the property MyDbType changes, the combobox changes not.
XAML:
<Window.Resources>
<ObjectDataProvider x:Key="dbEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="utils:DbType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<ComboBox Margin="0" Name="comboDbType" VerticalAlignment="Center" Grid.Row="1" Height="25"
ItemsSource="{Binding Source={StaticResource dbEnum}}"
SelectedItem="{Binding Path=CurrDbSettings.MyDbType,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:MainWindow}},
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Grid.ColumnSpan="1" Grid.Column="1">
</ComboBox>
Any hints?
The property
MyDbTypeneeds to somehow tell the binding system that it has changed. For that, there is theINotifyPropertyChangedinterface which you need to implement on the CurrDbSettings object’s class and rise thePropertyChangedevent in the setter of theMyDbTypeproperty. Something like this: