title: Wpf MVVM one ObservableCollection multiple ListViews
body: <p>in my MainView I added a <code>UserControl</code></p>
  
  <pre><code>&lt;TabItem Header="Current Elements"&gt;
                  &lt;tabData:CurrentElementsControl DataContext="{Binding Path=EditorViewModel.SelectedConfigFile}"&gt;&lt;/tabData:CurrentElementsControl&gt;
              &lt;/TabItem&gt;
  </code></pre>
  
  <p>and set its <code>DataContext</code>. The <code>SelectedConfigFile</code> got an <code>ObservableCollection&lt;Elements&gt;</code> 
  where different types of elements are stored.</p>
  
  <p>My <code>UserControl</code> is basically a <code>ListView</code></p>
  
  <pre><code>&lt;ListView Name="ServiceListView"
                                            ItemsSource="{Binding Path=Elements}"                                              
                                            SelectedItem="{Binding Path=SelectedElement, Mode=TwoWay}"
                                            Loaded="ServiceListView_Loaded"/&gt;
  </code></pre>
  
  <p>where i want to display items of the <code>ObservableCollection&lt;Elements&gt;</code> of a given type.
  But I dont want to add another <code>ObservableCollection</code> to the <code>SelectedConfigFile</code> (The VM) for every type and listview. So I thought I could just set a Filter for my UserControl, using its Loaded event like this (in codebehind):</p>
  
  <pre><code>        private void ServiceListView_Loaded(object sender, RoutedEventArgs e)
      {
          CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(this.ServiceListView.ItemsSource);
          view.Filter = ServiceFilter;
      }
  
          private bool ServiceFilter(object item)
      {           
          if (item is ServiceViewModel ) {
              return true;
          }
          else {
              return false;
          }
      }
  </code></pre>
  
  <p>But this will filter the <code>ObservableCollection&lt;Elements&gt;</code> aswell, which I need (unfiltered) in other places. Any suggestions?</p>
  
  <p>Thank you in advance!</p>