title: Getting TreeViewItem for the selected item in a TreeView
body: <p>I have a TreeView that is bound to a dataset which is having parent child relation. How i will get seleted TreeViewItem from the TreeView? Please help me. My code is  below.</p>
  
  <p>xaml:-</p>
  
  <pre><code>&lt;TreeView Name="tvPersonal"  Background="Transparent"  ItemsSource="{Binding RootNodes}" SelectedItemChanged="tvPersonal_SelectedItemChanged"&gt;    
   &lt;TreeView.ItemTemplate&gt;
     &lt;HierarchicalDataTemplate ItemsSource="{Binding rsParentChild}"&gt;
       &lt;TextBlock Text="{Binding Name}" /&gt;
     &lt;/HierarchicalDataTemplate&gt;
   &lt;/TreeView.ItemTemplate&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code> public MainWindow()   
  
          {    
              InitializeComponent();    
              DataSet ds = new BL.BLMenu().GetAllMenues(new BOModule { Name = Modules.Personnel });
              ds.Tables[0].TableName = "Menu";
              DataRelation relation = new DataRelation("rsParentChild",
                      ds.Tables["Menu"].Columns["MenuId"],
                      ds.Tables["Menu"].Columns["ParentId"]);
              relation.Nested = true;    
              ds.Relations.Add(relation);
              BOMenu mnu = new BOMenu();    
              BOMenu.RootNodes = ds.Tables["Menu"].DefaultView;
              BOMenu.RootNodes.RowFilter = "ParentId IS NULL";    
  
              this.DataContext = this;
              stbiDate.Content = DateTime.Now;
  
          }
          public DataView RootNodes    
          {
              get { return BOMenu.RootNodes; }
          }
  </code></pre>
  
  <p>BOMenu Class :-</p>
  
  <pre><code> public class BOMenu
      {
          public string MenuId
          {
              get;
              set;
          }
  
          public string Name
          {
              get;
              set;
          }
  
          public string ParentId
          {
              get;
              set;
          }
  
          public int Priority
          {
              get;
              set;
          }
  
          public static DataView RootNodes
          {
              get;
              set;
          }
  
      }
  </code></pre>