title: How to Bind data to DataGridComboBoxColumn in DataGrid using MVVM
body: <p>This is driving me crazy. I have a DataGrid which has a DataGridComboBoxColumn which I want the user to be able to use to select from. This is the basic outline of my grid.</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding GoalList}" DockPanel.Dock="Bottom" AutoGenerateColumns="False"&gt;
  &lt;DataGrid.Columns&gt;
  &lt;DataGridComboBoxColumn ItemsSource="{Binding LifeAreaList}" Header="Life Area"/&gt;
  &lt;DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>The DataGrid is bound to a collection of objects of type Goal. Each Goal has a property of type LifeArea. Each LifeArea has the properties LifeAreaId and Name.</p>
  
  <p>The data context contains an observable collection of Goals: GoalList and a list of Life Areas: LifeAreaList. I want the user to be able to select a different life area for a goal. Also the name of the life area needs to be the displayed value.</p>
  
  <p>EDIT</p>
  
  <hr>
  
  <p>The solution is that the ItemsSource for the DataGridComboBoxColumn has to be set as a static resource. Another option is to set the ItemsSource through code.</p>
  
  <p>In the end I have:</p>
  
  <pre><code>&lt;DataGridComboBoxColumn x:Name="_lifeAreaComboBoxColumn" SelectedItemBinding="{Binding LifeArea}" DisplayMemberPath="Name" Header="Life Area"&gt;
  </code></pre>
  
  <p>In the code behind I set the ItemsSource:</p>
  
  <pre><code>_lifeAreaComboBoxColumn.ItemsSource = LifeAreaDAL.GetLifeAreas();
  </code></pre>
  
  <p>When I get a chance I'll convert this to a StaticResource.</p>