我有这样的数据绑定设置:
ItemsSource="{Binding Source={my:Enumeration {x:Type credit:OccupationCategory}}}"
DisplayMemberPath="Description"
SelectedValue="{Binding EmplType}"
SelectedValuePath="Value"/>
它工作得非常好。对较大的软件设计进行更改我不能再拥有任何生成 INotifyPropertyChanged 事件的东西,因此这种类型的数据绑定不起作用。相反,我手动设置 selectedIndex 并从如下代码构建选项:
ItemsSource="{Binding Source={StaticResource ResidenceOwnershipType}}"/>
其中引用
<UserControl.Resources>
<ObjectDataProvider x:Key="ResidenceOwnershipType" MethodName="GetValues" ObjectType="{x:Type System:Enum}" >
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="credit:ResidenceOwnershipType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</UserControl.Resources>
就列表选项的构建和我所有数据的链接而言,这是有效的,但我无法让组合框在枚举中显示描述标签而不是实际文本。
我试过这样的事情:
DisplayMemberPath="Description"
但那是不正确的。我该怎么做呢?
编辑:
我的枚举:
[DataContract]
public enum ResidenceOwnershipType
{
[Description("")]
None = 0,
[Description("Owns Home Outright")]
OwnsHomeOutright = 1,
[Description("Buying Home")]
BuyingHome = 2,
[Description("Renting/Leasing")] //Weird order here reflects RouteOne website
RentingLeasing = 4,
[Description("Living w/Relatives")]
LivingWithRelatives = 3,
[Description("Owns/Buying Mobile Home")]
MobileHome = 5,
[Description("Unknown")]
Unknown = 6
}