I Have an enum like bellow
And the converter
As you can see, what i want is the Description will show the enum type as Display with string get from EnumDisplayConverter, and the result should be look like this.
but when i use with Syncfusion SfDatagrid like bellow
Then the Description Column just show Display string when i enter to editmode , and if i breakout of editmode , i become enum string value , show show display string as i need, can you help me what i need to do, thanks.
this is what i get when use with SfDataGrid.
|
<syncfusion:SfDataGrid ItemsSource="{Binding Orders}"
AutoGenerateColumnsForCustomType="True"
AutoGenerateColumnsModeForCustomType="Child"
ColumnSizer="SizeToHeader"
AllowEditing="True"
SelectionMode="Extended"
AutoGeneratingColumn="OnAutoGeneratingColumn"
AllowSorting="False"
AllowFiltering="False"
x:Name="sfDataGrid" >
</syncfusion:SfDataGrid> |
|
private void OnAutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)
{
if (e.Column.MappingName == "Description")
{
((e.Column as GridComboBoxColumn).DisplayBinding as Binding).Converter = new EnumDisplayNameConverter();
}
} |
|
public class EnumDisplayNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var display = value.GetType()?.GetMember(value.ToString())?.First().GetCustomAttribute<DisplayAttribute>();
return display.Name;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |