我的数据绑定设置如下:
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
}