I have a comboxBox column in my xamDataGrid.
I needed to display enum values in the combobox dropdown list that are converted to user friendly values.
I was able to display user friendly values in the comboBox dropdown but when the selection is made and I got out of editing mode, the string converted back to the regular enum values (ie. "s1" "s2" etc).
public enum ScanSpeed { [Description("Fast")]s1 = 0,
[Description("Very Fast")]s2 = 1,
[Description("Super Fast")]s3 = 2,
}
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="ScanSpeedEnumValues"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="model:ScanSpeed" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider>
<dge:ComboBoxItemsProvider x:Key="ScanSpeedTypes"> <dge:ComboBoxItemsProvider ItemsSource="{Binding Source={StaticResource ScanSpeedEnumValues}}" /> </dge:ComboBoxItemsProvider>
<converter:EnumToUserFriendlyNameConverter x:Key="ScanSpeedEnumConverter" />
<Style x:Key="ScanSpeedFieldStyle" TargetType="{x:Type dge:XamComboEditor}"> <Setter Property="ItemsProvider"> <Setter.Value> <dge:ComboBoxItemsProvider ItemsSource="{Binding Source={StaticResource ScanSpeedEnumValues}, Converter={StaticResource ScanSpeedEnumConverter}}"/> </Setter.Value> </Setter> <Setter Property="IsEditable" Value="False"/> </Style>
Can you give example on how to do this?
Hello Marlon,
Thank you for your post!
I have been looking into your question and have created a small sample application for you. In the sample application I have a simple xamDataGrid bind to a collection, that has an enum property. I use a class - EnumDescriptionkWrapper - that gets the Description attribute of the enum values. Then I set the enums collection as ItemsSource for the XamComboEditor.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.
This is exactly what I'm looking for. It worked beautifully!
Thank you so much!
Thank you for the feedback. I am glad I was able to help.