Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
320
ComboBox column converting enum values to user friendly values and back.
posted

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?