title: wpf referencing value converter from within nested datatemplate (causing null reference exception)
body: <p>I am experiencing troubles with IValueConverters called from <strong>nested datatemplate</strong> (ListViewItems).</p>
  
  <p>I have complex (list of) objects containing other objects and lists of lists of objects (too much source code to put it all here)...</p>
  
  <p>Everything works fine except the IValueConverter Implementation on deeper nesting levels...</p>
  
  <p>Simplifyed and shortened XAML:</p>
  
  <pre><code>    &lt;Window x:Class="XXXX.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:converter="clr-namespace:XXXX.Converter"
      Width="800"
      Height="600"
      Icon="/Images/Icons/Calendar.ico"
      Loaded="Window_Loaded"
      Style="{StaticResource WindowDefaultStyle}"
      WindowState="Maximized"&gt;
  &lt;Window.Resources&gt;
      &lt;!--  &lt;converter:ValueToVisibilityConverter x:Key="ValueToVisibility" /&gt;  --&gt;
      &lt;converter:PercentageConverter x:Key="PercentFromValue" /&gt;
      &lt;converter:SubtractionConverter x:Key="SubstractFromValue" /&gt;
      &lt;converter:SingleTextLineConverter x:Key="inSingleLine" /&gt;
      &lt;converter:B2VConverter x:Key="B2V" /&gt;
  &lt;/Window.Resources&gt;
  
      &lt;Grid Name="grid_Supplier"&gt;
          &lt;ListView Name="listview_Product"
              Grid.Row="1"
              Height="{Binding ElementName=grid_Supplier,
              Path=ActualHeight,
              Converter={StaticResource SubstractFromValue},
              ConverterParameter=60}"
              ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
              AncestorType=Window},Path=SuppliersProducts}"&gt;
                  &lt;ListView.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;ListView Name="listview_CM"
                                  Width="{Binding ElementName=grid_SupplierProduct,
                                  Path=ActualWidth,
                                  Converter={StaticResource PercentFromValue},
                                  ConverterParameter=80}"
                                  ItemsSource="{Binding CM}"&gt;
                                  &lt;ListView.ItemTemplate&gt;
                                      &lt;DataTemplate&gt;
                                          &lt;ListView Name="listview_Comments"
                                              ItemsSource="{Binding Comments}"&gt;
                                              &lt;ListView.ItemTemplate&gt;
                                                  &lt;DataTemplate&gt;
                                                      &lt;TextBlock
                                                              Text="{Binding Comment.DueDate, StringFormat='dd.MM.yyyy'}"
                                                              Background="{Binding Status
  </code></pre>
  
  <p><strong>, Converter={StaticResource B2V}</strong></p>
  
  <pre><code>}"/&gt;
                                                  &lt;/DataTemplate&gt;
                                              &lt;/ListView.ItemTemplate&gt;
                                          &lt;/ListView&gt;
                                      &lt;/DataTemplate&gt;
                                  &lt;/ListView.ItemTemplate&gt;
                          &lt;/ListView&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListView.ItemTemplate&gt;
          &lt;/ListView&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>as you can see there are 3 nested ListViews, the converter (PercentFromValue) in the "first" level is working without problems - with Binding and Parameter...</p>
  
  <p>My problem are at the next nesting "levels" as soon as the Converter part (<strong>StaticResource B2V</strong>) of the Binding is present, Null reference exception is risen at Runtime (no further explanations or nested exception infos are available... - but as soon as the converter is gone there is no problem... OK no exception, but also no Background - as has to be expected... )</p>
  
  <p>I have tried to create "listview resource" part, but there is also Null reference exception risen (I assume the "converter:" part of the path can not be found in that case.</p>
  
  <p>Since I am using Backgroundworker (information shown on the gui is collected from more than 9 related tables), there is no possibility to pass Brush to the gui (inherits from Dispatcher and causes "DependencySource must be created in same thread as DependencyProperty" Error).</p>
  
  <p>Now I am preparing all in the Background and adding only the Background-Brush in the same thread as workaround, but it is ugly...</p>
  
  <p>It will be much better to use the converter, but <strong>how to reference it from within the nested datatemplate?</strong></p>
  
  <p>Thank you very much in advance for your help!</p>