Search code examples
wpfbindingdatagriddatagridcomboboxcolumn

Easy way to specify Enum type as DataGridComboboxColumn ItemsSource (using DataGrid.Resources is too verbose)?


I know I can bind DataGridComboboxColumn's ItemsSource to enum members like this:

<DataGrid.Resources>
  <ObjectDataProvider x:Key="genderEnum" MethodName="GetValues" 
    ObjectType="{x:Type sys:Enum}">
  <ObjectDataProvider.MethodParameters>
    <x:Type Type="local:Gender"/>
  </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
...
<DataGridComboBoxColumn 
  Header="Gender"
  SelectedItemBinding="{Binding Gender}"
  ItemsSource="{Binding Source={StaticResource genderEnum}}"/>

The question is: Is there a faster (not so verbose) way?


Solution

  • Well, currently I ended up with the following solution:
    https://stackoverflow.com/a/880175
    (Involves writing a simple markup extension and when using it for setting ItemsSource)