Wpf 将combobox选定值绑定到属性

Wpf 将combobox选定值绑定到属性,wpf,binding,combobox,Wpf,Binding,Combobox,我有一个枚举动物,里面有Fish和Cat值 public ObservableCollection<AnimalsEnum> Animals { get; set; } publicobservableCollection动物{get;set;} 我绑定要在组合框中显示的枚举 <ComboBox ItemsSource="{Binding Path=Animals }"> 我还有一个名为AnimalsChanged的属性,类型为AnimalsEnum 当我从组合

我有一个枚举动物,里面有Fish和Cat值

public ObservableCollection<AnimalsEnum> Animals { get; set; }
publicobservableCollection动物{get;set;}
我绑定要在组合框中显示的枚举

<ComboBox ItemsSource="{Binding Path=Animals }">

我还有一个名为AnimalsChanged的属性,类型为AnimalsEnum

当我从组合框中选择动物时,我需要一个名为AnimalsChanged的属性从组合框中获取枚举值

<ComboBox ItemsSource="{Binding Path=Animals }">
如何从xaml执行此操作?有什么想法吗


谢谢

使用
SelectedItem
绑定列表中的实际数据项。使用
SelectedValue
可以从
SelectedItem
绑定特定属性。默认情况下,它是双向绑定的,因此您无需指定:

<ComboBox ItemsSource="{Binding Path=Animals }" SelectedItem="{Binding AnimalsChanged}">

非常感谢您的快速回答。评价它。