title: WPF: TreeViewItem bound to an ICommand
body: <p>I am busy creating my first MVVM application in WPF. </p>
  
  <p>Basically the problem I am having is that I have a TreeView (System.Windows.Controls.TreeView) which I have placed on my WPF Window, I have decide that I will bind to a ReadOnlyCollection of CommandViewModel items, and these items consist of a DisplayString, Tag and a RelayCommand.</p>
  
  <p>Now in the XAML, I have my TreeView and I have successfully bound my ReadOnlyCollection to this. I can view this and everything looks fine in the UI. </p>
  
  <p>The issue now is that I need to bind the RelayCommand to the Command of the TreeViewItem, however from what I can see the TreeViewItem doesn't have a Command. Does this force me to do it in the IsSelected property or even in the Code behind TreeView_SelectedItemChanged method or is there a way to do this magically in WPF? </p>
  
  <p>This is the code I have:</p>
  
  <pre><code>&lt;TreeView BorderBrush="{x:Null}" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch"&gt;
  &lt;TreeView.Items&gt;
      &lt;TreeViewItem
          Header="New Commands"
          ItemsSource="{Binding Commands}"
          DisplayMemberPath="DisplayName"
          IsExpanded="True"&gt;
      &lt;/TreeViewItem&gt;
  &lt;/TreeView.Items&gt;
  </code></pre>
  
  <p></p>
  
  <p>and ideally I would love to just go: </p>
  
  <pre><code>&lt;TreeView BorderBrush="{x:Null}" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch"&gt;
  &lt;TreeView.Items&gt;
      &lt;TreeViewItem
          Header="New Trade"
          ItemsSource="{Binding Commands}"
          DisplayMemberPath="DisplayName"
          IsExpanded="True"
          Command="{Binding Path=Command}"&gt;
      &lt;/TreeViewItem&gt;
  &lt;/TreeView.Items&gt;
  </code></pre>
  
  <p></p>
  
  <p>Does someone have a solution that allows me to use the RelayCommand infrastructure I have.</p>
  
  <p>Thanks guys, much appreciated!</p>
  
  <p>Richard</p>