title: Cannot bind view programmatically in Caliburn.Micro
body: <p>I checked out the following thread and followed the example to try and bind a view dynamically:
  <a href="https://stackoverflow.com/questions/6333032/caliburn-micro-create-and-bind-view-programmatically">Caliburn.Micro: Create and Bind View programmatically</a></p>
  
  <p>My main view has a DataGrid with the following XAML:</p>
  
  <pre><code>&lt;DataGrid Name="DataGridTestSuites" Grid.Row="1" 
        HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="12"
        IsReadOnly="True" AutoGenerateColumns="False"
        ItemsSource="{Binding TestSuites}"
        RowDetailsVisibilityMode="VisibleWhenSelected"
        cal:Message.Attach="[Event RowDetailsVisibilityChanged] = [Action PopulateTestSuiteDetail($this, $eventArgs)]"&gt;
  &lt;DataGrid.Columns&gt;
      &lt;DataGridTextColumn Header="Name" Binding="{Binding Name}" /&gt;
      &lt;DataGridTextColumn Header="Category" Binding="{Binding Category}" /&gt;
      &lt;DataGridTextColumn Header="Assembly" Binding="{Binding AssemblyPath}" /&gt;
  &lt;/DataGrid.Columns&gt;
  &lt;DataGrid.RowDetailsTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;StackPanel x:Name="StackPanelTestSuiteDetail" /&gt;
      &lt;/DataTemplate&gt;
  &lt;/DataGrid.RowDetailsTemplate&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>Note the StackPanel in the DataTemplate. This is where I want to inject my sub-view.</p>
  
  <p>My view model has a function named PopulateTestSuiteDetails() which is attached to the RowDetailsVisibilityChanged event as described in the XAML:</p>
  
  <pre><code>public void PopulateTestSuiteDetail(DataModels.TestSuite testSuite, object eventArgs)
  {
      if (!(eventArgs is DataGridRowDetailsEventArgs)) return;
  
      StackPanel stackPanel = (StackPanel)((DataGridRowDetailsEventArgs)eventArgs).DetailsElement.FindName("StackPanelTestSuiteDetail");
  
      var methodViewModel = IoC.Get&lt;TestSuiteHelperMethodViewModel&gt;();
  
      var methodView = new Harness.Views.TestSuiteHelperMethodView();
  
      stackPanel.Children.Add(methodView);
      ViewModelBinder.Bind(methodViewModel, methodView, null);
  }
  </code></pre>
  
  <p>The function does get invoked correctly when I debug my program. However, it doesn't seem like my sub-view is being attached properly (my sub-view has a basic button and it is not visible when a data grid row is in focus.) Any idea why?</p>