If you bind the SelectedItem of the ComboBox to an underlying class, you should be able to change the binding by changing that class.
For example, let's say your enum was called "Country" and you had a class called "Person" and that person had a property called "CountryOfOrigin" and you want to bind it to a ComboBox. You could do this:
XAML file:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestingWPF"
x:Class="TestingWPF.TestWindow">
<Window.Resources>
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type local:Country}"
x:Key="Countries">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:Country" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<StackPanel>
<ComboBox x:Name="comboBox"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="100" Margin="10"
ItemsSource="{Binding Source={StaticResource Countries}}"
SelectedItem="{Binding Path=CountryOfOrigin, Mode=TwoWay}"/>
<Button HorizontalAlignment="Center" Content="Change Country to Mexico" Margin="10" Click="Button_Click"/>
</StackPanel>
</Window>
Code-behind:
public partial class TestWindow : Window
{
Person p;
public TestWindow()
{
InitializeComponent();
p = new Person();
p.CountryOfOrigin = Country.Canada;
DataContext = p;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
p.CountryOfOrigin = Country.Mexico;
}
}
public enum Country
{
Canada,
UnitedStates,
Mexico,
Brazil,
}
public class Person : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private Country _countryOfOrigin;
public Country CountryOfOrigin
{
get
{
return _countryOfOrigin;
}
set
{
if (_countryOfOrigin != value)
{
_countryOfOrigin = value;
PropertyChanged(this, new PropertyChangedEventArgs("CountryOfOrigin"));
}
}
}
}