title: WPF MVVM TreeView selected item not populating current selection object
body: <p>I'm using WCF and MVVM pattern to populate a tree view control and I need the selected item passed as a parameter for another method in the view model (to populate a different control).  </p>
  
  <p>The treeview populates just fine but the selected value is not being passed to the view model. e.g. in the viewmodel:</p>
  
  <pre><code>    private ICollectionView m_SuppliersView;
      public ObservableCollection&lt;SupplierItem&gt; SupplierItems
      {
          get
          {
              return supplierItems;
          }
          private set
          {
              if (supplierItems == value)
              {
                  return;
              }
              supplierItems = value;
              OnPropertyChanged("SupplierItems");
          }
      }
      public SupplierItem CurrentSupplier
      {
          get
          {
              if (m_SuppliersView != null)
              {
                  return m_SuppliersView.CurrentItem as SupplierItem;
              }
  
              return null;
          }
      }
     private void OnCollectionViewCurrentChanged(object sender, EventArgs e)
      {
  // view model is inherited from a base class.  base method listed below
          OnPropertyChanged("CurrentSupplier");   
      }
  
     protected virtual void OnPropertyChanged(string propertyName)
      {
          VerifyPropertyName(propertyName);
  
          var handler = PropertyChanged;
          if (handler != null)
          {
              var e = new PropertyChangedEventArgs(propertyName);
              handler(this, e);
          }
      }
  
      private void Load() // Load event to populate the treeview source object
      { 
  // SupplierItems object is populated just fine and treeview displays just fine so I won't show how the sausage is made.   I believe the issue is here:  
          m_SuppliersView = CollectionViewSource.GetDefaultView(SupplierItems);
  
          if (m_SuppliersView != null)
          {
              m_SuppliersView.CurrentChanged += OnCollectionViewCurrentChanged;
          }
  
          OnPropertyChanged("CurrentSupplier");
  </code></pre>
  
  <p>in the xaml:</p>
  
  <pre><code>&lt;Window.Resources&gt;
         &lt;HierarchicalDataTemplate x:Key="SuppiersDistributorsTemplate" ItemsSource="{Binding Children}"&gt;
            &lt;TextBlock Text="{Binding ManagedLocationName}"/&gt;
         &lt;/HierarchicalDataTemplate&gt;
  &lt;/Window.Resources&gt;
  
  
  &lt;TreeView x:Name="tvSuppliers" ItemsSource="{Binding SupplierItems}" 
            ItemTemplate="{StaticResource SuppiersDistributorsTemplate}" 
            SelectedValuePath="CurrentSupplier"&gt;              
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>Any thoughts on this?<br>
  When I set a breakpoint in the method "OnCollectionViewCurrentChanged", nothing ever happens when I click on a treeview node. i.e. "CurrentSupplier" never gets updated, so I can't use CurrentSupplier in another method I have (to load a collection for another control). </p>
  
  <p>Thanks</p>