title: Dynamic filtering with an ItemsControl combobox
body: <p>I have this situation where I want to display a list of Administration objects and a <code>ComboBox</code> for each Administration. Inside this <code>ComboBox</code> I want a list with Employees belonging to this Administration, along with an empty option. So I need to filter based on Administration.</p>
  
  <p>So far I've come up with the following code (note: object names have been translated)</p>
  
  <pre><code>&lt;ItemsControl x:Name="listAdministrations" ItemsSource="{Binding Path=AllAdministrations}" Margin="0,0,0,6"&gt;
      &lt;ItemsControl.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel Orientation="Vertical" &gt;
                  &lt;TextBox Content="{Binding Path=AdministrationName}" /&gt;
  
                  &lt;StackPanel Orientation="Horizontal" Margin="14,0,0,0"&gt;
                      &lt;Label&gt;Declares under:&lt;/Label&gt;
                      &lt;ComboBox DisplayMemberPath="DisplayFullName"&gt;
                          &lt;ComboBox.ItemsSource&gt;
                              &lt;CompositeCollection&gt;
                                  &lt;!-- empty option --&gt;
                                  &lt;model:Employee DisplayFullName="-" /&gt;
                                  &lt;CollectionContainer Collection="{Binding Source={StaticResource employeeCV}}"/&gt;
                              &lt;/CompositeCollection&gt;
                          &lt;/ComboBox.ItemsSource&gt;
                      &lt;/ComboBox&gt;
                  &lt;/StackPanel&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>The static resource <code>employeeCV</code> is a <code>CollectionViewSource</code> with a Filter event attached. But I have to somehow pass the current Administration in the ItemsControl loop to this event. In data binding, this translates to <code>{Binding Path=.}</code> within the <code>ItemsControl</code>. The sender object is my <code>CollectionViewSource</code> but this provides no useful data.</p>
  
  <p>Something like this:</p>
  
  <pre><code>private void EmployeeAdministrationFilter( object sender, FilterEventArgs e )
      {
          Employee employee = ( Employee )e.Item;
          Administration administration; // how do I pass the administration to this filter?
  }
  </code></pre>