title: WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?
body: <p>(Note - this is a re-post as my first question got posted under wrong headline: <a href="https://stackoverflow.com/questions/4484430/in-wpf-mvvm-should-viewmodel-be-involved-in-opening-a-windog-e-g-about-window">Here</a> Sorry!)</p>
  
  <p>I have a standard WPF treeview and have bound items to view model classes.</p>
  
  <p>I now wish to handle behaviour when items are double-clicked (opening documents visual-studio-style).</p>
  
  <p>I can get event-handler to fire in the control housing the treeview (xaml shown), but how do I bind to specific behaviour on the view model classes - e.g. ProjectViewModel?</p>
  
  <p>Preferable bound to ICommand-implementer, as this is used elsewhere...</p>
  
  <pre><code>&lt;TreeView ItemsSource="{Binding Projects}" MouseDoubleClick="TreeView_MouseDoubleClick"&gt;
      &lt;TreeView.ItemContainerStyle&gt;
          &lt;!-- 
  This Style binds a TreeViewItem to a TreeViewItemViewModel. 
  --&gt;
          &lt;Style TargetType="{x:Type TreeViewItem}"&gt;
              &lt;Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /&gt;
              &lt;Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /&gt;
              &lt;Setter Property="FontWeight" Value="Normal" /&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property="IsSelected" Value="True"&gt;
                      &lt;Setter Property="FontWeight" Value="Bold" /&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/TreeView.ItemContainerStyle&gt;
  
      &lt;TreeView.Resources&gt;
          &lt;HierarchicalDataTemplate DataType="{x:Type Implementations:ProjectViewModel}" ItemsSource="{Binding Children}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Image Width="16" Height="16" Margin="3,0" Source="Images\Region.png" /&gt;
                  &lt;TextBlock Text="{Binding DisplayName}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/HierarchicalDataTemplate&gt;
  
          &lt;HierarchicalDataTemplate DataType="{x:Type Implementations:PumpViewModel}" ItemsSource="{Binding Children}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Image Width="16" Height="16" Margin="3,0" Source="Images\State.png" /&gt;
                  &lt;TextBlock Text="{Binding Name}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/HierarchicalDataTemplate&gt;
  
          &lt;DataTemplate DataType="{x:Type Implementations:PumpDesignViewModel}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Image Width="16" Height="16" Margin="3,0" Source="Images\City.png" /&gt;
                  &lt;TextBlock Text="{Binding Name}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/TreeView.Resources&gt;
  &lt;/TreeView&gt;
  </code></pre>