title: How to bind a list of a custom object to a DataGridComboboxColumn in WPF?
body: <p>I found some examples on this site, but I couldn't find anything which I can use In my case.</p>
  
  <p>I have a <code>DataGrid</code> with <code>AutoGeneratedColumn="False"</code> and <code>ViewModel</code> which is bind to the <code>DataContext</code> of my Window, in which the <code>DataGrid</code> is located.
  In my <code>ViewModel</code> I have a List of a data structure called <code>Model</code> which is bind to the <code>ItemsSource</code> property of my <code>DataGrid</code>.</p>
  
  <p>The model contains an <code>Enum</code>. I was able to generate a <code>DataGridComboboxColumn</code> for the enum, but I don't know how to archive the same for a list of objects.</p>
  
  <p>Here is my <code>Model.cs</code> class.</p>
  
  <pre><code>public class Model
  {
      public CType Type { get; set; }
      public Person Person { get; set; }
      public Condition Condition { get; set; }
  }
  
  public class Person
  {
      public List&lt;Trait&gt; Traits { get; set; }
      public string Name { get; set; }
  }
  
  public class Condition
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public int Value { get; set; }
  }
  
  public class Trait
  {
      public string Name { get; set; }
      public List&lt;Reason&gt; Reasons { get; set; }
  }
  
  public class Reason
  {
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>Here is my <code>ViewModel.cs</code> class, with pre-populated objects of Type <code>Model</code>.</p>
  
  <pre><code>public class ViewModel
  {
      //Bind to Grid - ItemsSource
      public ObservableCollection&lt;Model&gt; Models { get; set; }
  
      //Possible ComboboxValues for Column: Model.Person
      public ObservableCollection&lt;Person&gt; Persons { get; set; }
  
      //Possible ComboboxValues for Column: Model.Condition
      public ObservableCollection&lt;Condition&gt; Conditions { get; set; }
  
      public ViewModel()
      {
          Models = new ObservableCollection&lt;Model&gt;();
  
          #region Model1
          Model model = new Model();
          model.Condition = new Condition()
          {
              Id = 1,
              Name = "Hallo",
              Value = 5
          };
          model.Type = CType.One;
          model.Person = new Person()
          {
              Name = "Peter",
              Traits = new List&lt;Trait&gt;()
              {
                  new Trait()
              {
                  Name = "Trait 1",
                  Reasons = new List&lt;Reason&gt;()
                  {
                      new Reason() { Name = "Reason 1" },
                      new Reason() { Name = "Reason 2" }
                  }
              },
              new Trait()
              {
                  Name = "Trait 2",
                  Reasons = new List&lt;Reason&gt;()
                  {
                      new Reason() { Name = "Reason 3" },
                      new Reason() { Name = "Reason 4" }
                  }
              }
              }
          };
          #endregion
  
          #region Model2 
          Model model2 = new Model();
          model2.Condition = new Condition()
          {
              Id = 1,
              Name = "Welt",
              Value = 5
          };
          model2.Type = CType.Three;
          model2.Person = new Person()
          {
              Name = "Manuel",
              Traits = new List&lt;Trait&gt;()
              {
                  new Trait()
                  {
                      Name = "Trait 3",
                      Reasons = new List&lt;Reason&gt;()
                      {
                          new Reason() { Name = "Reason 5" },
                          new Reason() { Name = "Reason 6" }
                      }
                  },
                  new Trait()
                  {
                      Name = "Trait 4",
                      Reasons = new List&lt;Reason&gt;()
                      {
                          new Reason() { Name = "Reason 7" },
                          new Reason() { Name = "Reason 8" }
                      }
                  }
              }
          };
          #endregion
  
          Persons = new ObservableCollection&lt;Person&gt;()
          {
              model.Person, model2.Person
          };
  
          Conditions = new ObservableCollection&lt;Condition&gt;()
          {
              model.Condition, model2.Condition
          };
  
          Models.Add(model);
          Models.Add(model2);
      }
  }
  </code></pre>
  
  <p>And this is my <code>Window.xaml</code> file with the working enum example.
  Last but not least you have the set the <code>DataContext</code> property to a new instance of the <code>ViewModel</code> class in code behind.</p>
  
  <pre><code>&lt;Window x:Class="WpfApp2.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:WpfApp2"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      mc:Ignorable="d"
      Title="MainWindow" Height="450" Width="800"&gt;
  &lt;Window.Resources&gt;
      &lt;ObjectDataProvider x:Key="myEnumData"
              MethodName="GetValues" 
              ObjectType="{x:Type sys:Enum}"&gt;
          &lt;ObjectDataProvider.MethodParameters&gt;
              &lt;x:Type TypeName="local:CType" /&gt;
          &lt;/ObjectDataProvider.MethodParameters&gt;
      &lt;/ObjectDataProvider&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Models}"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridComboBoxColumn 
                  Header="Enum"
                  ItemsSource="{Binding Source={StaticResource myEnumData}, Mode=OneWay}"
                  SelectedValueBinding="{Binding Path=Type}"&gt;
              &lt;/DataGridComboBoxColumn&gt;
  
              &lt;!--ComboBox for Persons--&gt;
              &lt;DataGridComboBoxColumn&gt;
  
              &lt;/DataGridComboBoxColumn&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>