I had databinding set up like this:
ItemsSource="{Binding Source={my:Enumeration {x:Type credit:OccupationCategory}}}"
DisplayMemberPath="Description"
SelectedValue="{Binding EmplType}"
SelectedValuePath="Value"/>
and it worked really well. Do to a change in the larger software design I can no longer have anything that generates an INotifyPropertyChanged Event so that type of databinding doesn't work. Instead I am manually setting the selectedIndex and building the options from code like this:
ItemsSource="{Binding Source={StaticResource ResidenceOwnershipType}}"/>
which references
<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>
That works as far as the building of the list options is concerned and the linking of all of my data, but I can't get the comboboxes to show the description tag in the enumeration instead of the actual text.
I've tried something like this:
DisplayMemberPath="Description"
but that wasn't correct. How would I go about doing this?
EDIT:
My Enum:
[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
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…