title: WPF DataBinding issue: UserControls in DataGrid Cells not binding
body: <p>I am trying to build up a DataGrid control for managing a property grid. I have an abstract class for my parameter base class that parameters of various types implement. This base class contains variables that are shared across each parameter (like Group, Name, IsLocked, etc.), and then each parameter manages the information that relevant to the particular type. For example, a number parameter may use a slider for the user control, which also then uses min/max values, etc.</p>
  
  <p>I have set up a class which is an Observable Collection of my base parameter, and established it as a static resource for a CollectionViewSource:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;local:Parameters x:Key="Parameters"/&gt;
      &lt;CollectionViewSource x:Key="cvsParameters" Source="{StaticResource Parameters}" /&gt;
  &lt;/UserControl.Resources&gt;
  </code></pre>
  
  <p>Then in my DataGrid, I am using style triggers to switch between user controls for each of my parameters:</p>
  
  <pre><code>&lt;DataGrid x:Name="DataGrid_Globals"
            ItemsSource="{Binding Source={StaticResource cvsParameters}}"
            AutoGenerateColumns="False"
            CanUserAddRows="False"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True"/&gt;
          &lt;DataGridTemplateColumn Width="*" &gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;ContentControl&gt;
                          &lt;ContentControl.Style&gt;
                              &lt;Style TargetType="ContentControl"&gt;
                                  &lt;Style.Triggers&gt;
                                      &lt;DataTrigger Binding="{Binding UIType}" Value="Text"&gt;
                                          &lt;Setter Property="ContentTemplate"&gt;
                                              &lt;Setter.Value&gt;
                                                  &lt;DataTemplate&gt;
                                                      &lt;controls:ucText DataContext="{Binding}"/&gt;
                                                  &lt;/DataTemplate&gt;
                                              &lt;/Setter.Value&gt;
                                          &lt;/Setter&gt;
                                      &lt;/DataTrigger&gt;
                                      &lt;DataTrigger Binding="{Binding UIType}" Value="Number"&gt;
                                          &lt;Setter Property="ContentTemplate"&gt;
                                              &lt;Setter.Value&gt;
                                                  &lt;DataTemplate&gt;
                                                      &lt;controls:ucNumber DataContext="{Binding}"/&gt;
                                                  &lt;/DataTemplate&gt;
                                              &lt;/Setter.Value&gt;
                                          &lt;/Setter&gt;
                                      &lt;/DataTrigger&gt;
                                  &lt;/Style.Triggers&gt;
                              &lt;/Style&gt;
                          &lt;/ContentControl.Style&gt;
                      &lt;/ContentControl&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>My user controls are set up with their data context declared in XAML:</p>
  
  <pre><code>&lt;UserControl.DataContext&gt;
      &lt;local:TestNumber_cls/&gt;
  &lt;/UserControl.DataContext&gt;
  &lt;Grid HorizontalAlignment="Stretch"&gt;
      &lt;Slider 
          Value="{Binding NumberValue}" 
          Minimum="{Binding Min}" 
          Maximum="{Binding Max}" 
          /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I can't figure out how to ensure that my usercontrols bind correctly. My other column works fine, with each Key value appearing, being correctly bound and updating (for this example it's just the "Key" column, but all of the fields from the base class behave just fine.) The correct UserControls are also selected based on the UIType DataTrigger, but the UserControls just instantiate from an empty constructor and don't bind.</p>
  
  <p>I have also confirmed that standalone instances of my UserControls work fine and bind correctly. For, example, it works when I set the datacontext from code behind (which I don't want to do):</p>
  
  <pre><code>this.OneOffNumberUserControl.DataContext = ((Parameters)this.ParameterGrid.Resources["Parameters"])[2];
  </code></pre>
  
  <p>I have also tried to remove the DataContext="{Binding}" from my user controls, but this doesn't change anything.</p>