title: NullReferenceException loading RenderWindowControl for vtk in WPF
body: <p>I am trying to load a RenderWindowControl from vtk libraries on my WPF proyect using ActiViz.NET and Visual Studio 2013. The library works fine since I did a new project just to practice on itbut when I tried to integrate it into my work, I got a null RenderWindowControl this time. This is my code: </p>
  
  <p>MainWindow.xaml:</p>
  
  <pre><code>&lt;Window x:Class="myProject.Views.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:VtkTab="clr-namespace:myProject.Views.UITabs.VtkTab"
      x:Name="Mainwindow"
      MinHeight="600"
      MinWidth="800"
      Title="{Binding Title}"
      Height="720"
      Width="1280"
      Icon="{StaticResource ApplicationIcon}"
      Loaded="OnLoaded"
      DataContext="{Binding Main, Source={StaticResource ViewModelLocator}}"
      Style="{StaticResource WindowStyle}"
      mc:Ignorable="d"&gt;
  
      &lt;DockPanel&gt;
          &lt;TabControl&gt;
          ....
          ....
          &lt;VtkTab:VtkTabView /&gt;
          ....
          .... 
          &lt;/TabControl&gt;
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>VtkTabView.xaml:</p>
  
  <pre><code>&lt;UserControl x:Class="myProject.Views.UITabs.VtkTab.VtkTabView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:vtk="clr-namespace:Kitware.VTK;assembly=Kitware.VTK"
          Loaded="WindowLoaded"
          Height="480" Width="640"&gt;
          &lt;WindowsFormsHost Name="Wfh"&gt;
              &lt;vtk:RenderWindowControl x:Name="RenderControl" /&gt;
          &lt;/WindowsFormsHost&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>VtkTabView.xaml.cs:</p>
  
  <pre><code>public partial class UITabView
  {
  
      protected static Random _random = new Random();
      vtkActor actor = vtkActor.New();
  
      public VtkTabView()
      {
          InitializeComponent();
  
          var sphere = vtkSphereSource.New();
          sphere.SetThetaResolution(8);
          sphere.SetPhiResolution(16);
  
          var shrink = vtkShrinkPolyData.New();
          shrink.SetInputConnection(sphere.GetOutputPort());
          shrink.SetShrinkFactor(0.9);
  
          var move = vtkTransform.New();
          move.Translate(_random.NextDouble(), _random.NextDouble(), _random.NextDouble());
          var moveFilter = vtkTransformPolyDataFilter.New();
          moveFilter.SetTransform(move);
  
          moveFilter.SetInputConnection(shrink.GetOutputPort());
  
          var mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection(moveFilter.GetOutputPort());
  
          // The actor links the data pipeline to the rendering subsystem 
          actor.SetMapper(mapper);
          actor.GetProperty().SetColor(1, 0, 0);
      }
  
      private void WindowLoaded(object sender, RoutedEventArgs e)
      {
          var renderer = RenderControl.RenderWindow.GetRenderers().GetFirstRenderer();
          renderer.AddActor(actor);
      }
  }
  </code></pre>
  
  <p>RenderControl.RenderWindow is null on WindowLoaded (VtkTabView.xaml.cs) and I do not know why. Might it be because I load UITabView from a second xamp and I lose the content of RenderControl?, it is the only difference I see compare to the example I did. </p>