Why e.Source depends on TreeView populating method?
I have two trees: 

 1. fooTree - made up of <TreeViewItem> elements,
 2. barTree - constructed by <HierarchicalDataTemplate>

Both trees have MouseRightButtonDown event, but the e.Source type differs:

 1. fooTree - System.Windows.Controls.TreeViewItem
 2. barTree - System.Windows.Controls.TreeView

Why e.Source differs? Also, how can I get the clicked item for the barTree?

Markup:

        <TreeView Name="fooTree" MouseRightButtonDown="fooTree_MouseDown">
            <TreeViewItem Header="foo"></TreeViewItem>
            <TreeViewItem Header="foo"></TreeViewItem>
        </TreeView>
        
        <TreeView Name="barTree" MouseRightButtonDown="barTree_MouseDown" ItemsSource="{Binding BarItems}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate>
                    <TextBlock Text="{Binding}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>

Code:

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            this.DataContext = this;
        }
    
        public string[] BarItems
        {
            get { return new string[] { "bar", "bar" }; }
        }
    
        private void barTree_MouseDown(object sender, MouseButtonEventArgs e) 
        {
        }
    
        private void fooTree_MouseDown(object sender, MouseButtonEventArgs e) 
        {
        }
    }
Why e.Source depends on TreeView populating method?
===

I have two trees: 

 1. fooTree - made up of <TreeViewItem> elements,
 2. barTree - constructed by <HierarchicalDataTemplate>

Both trees have MouseRightButtonDown event, but the e.Source type differs:

 1. fooTree - System.Windows.Controls.TreeViewItem
 2. barTree - System.Windows.Controls.TreeView

Why e.Source differs? Also, how can I get the clicked item for the barTree?

Markup:

        <TreeView Name="fooTree" MouseRightButtonDown="fooTree_MouseDown">
            <TreeViewItem Header="foo"></TreeViewItem>
            <TreeViewItem Header="foo"></TreeViewItem>
        </TreeView>
        
        <TreeView Name="barTree" MouseRightButtonDown="barTree_MouseDown" ItemsSource="{Binding BarItems}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate>
                    <TextBlock Text="{Binding}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>

Code:

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            this.DataContext = this;
        }
    
        public string[] BarItems
        {
            get { return new string[] { "bar", "bar" }; }
        }
    
        private void barTree_MouseDown(object sender, MouseButtonEventArgs e) 
        {
        }
    
        private void fooTree_MouseDown(object sender, MouseButtonEventArgs e) 
        {
        }
    }