title: How can I bind the nested viewmodels to properties of a control
body: <p>I used Microsoft's Chart Control of the WPF toolkit to write my own chart control. 
  I blogged about it <a href="http://reyntjes.blogspot.com/2009/09/freeing-axes-of-microsoft-toolkit.html" rel="nofollow noreferrer">here</a>. My Chart control stacks the yaxes in the chart on top of each other. As you can read in the article this all works quite well. Now I want to create a viewmodel that controls the data and axes in the chart. So far I'm able to add axes to the chart and show them in the chart. But I have a problem when I try to add the lineseries because it has one DependentAxis and one InDependentAxis property. I don't know how to assign the proper xAxis and yAxis controls to it.<br>
  Below you see part of the LineSeriesViewModel. It has a nested XAxisViewModel and YAxisViewModel property.</p>
  
  <pre><code>public class LineSeriesViewModel : ViewModelBase, IChartComponent
  {
  
      XAxisViewModel _xAxis;
      public XAxisViewModel XAxis
      {
          get { return _xAxis; }
          set
          {
              _xAxis = value;
              RaisePropertyChanged(() =&gt; XAxis);
          }
      }
  
      //The YAxis Property look the same
  }
  </code></pre>
  
  <p>The viewmodels all have their own datatemplate.
  The xaml code looks like this:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;DataTemplate x:Key="xAxisTemplate" DataType="{x:Type l:YAxisViewModel}"&gt;
          &lt;chart:LinearAxis  x:Name="yAxis"  Orientation="Y" Location="Left" Minimum="0"  Maximum="10" IsHitTestVisible="False" Width="50" /&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate x:Key="yAxisTemplate" DataType="{x:Type l:XAxisViewModel}"&gt;
          &lt;chart:LinearAxis x:Name="xAxis"  Orientation="X" Location="Bottom" Minimum="0"  Maximum="100" IsHitTestVisible="False" Height="50" /&gt;
      &lt;/DataTemplate&gt;
  
      &lt;DataTemplate DataType="{x:Type l:LineSeriesViewModel}"&gt;
          &lt;!--Binding doesn't work on the Dependent and IndependentAxis! --&gt;
          &lt;!--YAxis XAxis and Series are properties of the LineSeriesViewModel --&gt;
          &lt;l:FastLineSeries DependentAxis="{Binding Path=YAxis}" 
                            IndependentAxis="{Binding Path=XAxis}"
                            ItemsSource="{Binding Path=Series}"/&gt;
      &lt;/DataTemplate&gt;
      &lt;Style TargetType="ItemsControl"&gt;
          &lt;Setter Property="ItemsPanel"&gt;
              &lt;Setter.Value&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;!--My stacked chart control --&gt;
                      &lt;l:StackedPanel x:Name="stackedPanel" Width="Auto" Height="Auto" Background="LightBlue"&gt;
                      &lt;/l:StackedPanel&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  &lt;/UserControl.Resources&gt;
  &lt;Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="True"&gt;
      &lt;!-- View is an ObservableCollection of all axes and series--&gt;
      &lt;ItemsControl x:Name="chartItems" ItemsSource="{Binding Path=View}" Focusable="False"&gt;
      &lt;/ItemsControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>This code works quite well. When I add axes they get drawn. But the DependentAxis and InDependentAxis of the lineseries control stay null, so the series doesn't get drawn. How can I bind the nested viewmodels to  the properties of a control?</p>