Q:

WPF - Treeview selected item index

I have a treeview panel. In the panel, there are several child nodes. Some of them are only a header.
The way I create the treeview:
treeviewpaneL.Items.Add(art);
art.Items.Add(prt);

some if statement....

TreeViewItem cldhdr = new TreeViewItem() { Header = "ChildNodes:" };
prt.Items.Add(cldhdr);
TreeViewItem cld = new TreeViewItem() .......
........
.....
cldhdr.Items.Add(cld);

Treeview:
Node1
  ChildNodes:           (This is header only.  It appears if child node exists)
   Childnode1
   Childnode2
   childnode3

Node2
Node3
  ChildNodes:           
   Childnode1
   Childnode2
   childnode3

Node4
Node5

In my treeview there are also images in front of all nodes. It's a code driven treeview. In the xaml part i have only:
<TreeView x:Name="treeviewpaneL" SelectedItemChanged="treeviewpaneL_SelectedItemChanged" >
                    </TreeView>

What I want to do is when I click on any of the treeview items, I need to get its index number.
My code is:
private void treeviewpaneL_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
    {

 int index = 0;
 ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(prt);

foreach (var _item in parent.Items)
        {

            if (_item == treeviewpaneL.SelectedItem)
            {
                selectedNodeIndex = index;
                MessageBox.Show(selectedNodeIndex.ToString());
                break;
            }
            index++;
        }
 } 

With the code above, I can get the index of Node1,Node2,Node3, Node4 and Node5 as 0,1,2,3,4
What I want is to get the index numbers as:
Node1  = 0
Childnode1 = 1       (Skipping the header)
Childnode2 = 2
Childnode3 = 3
Node2  = 4
....
....
....

What am I missing?

A:

Here is the solution, first of all your "MyTreeViewItem" 
public class MyTreeViewItem :TreeViewItem
{
    private int _index;
    public int Index
    {
        get { return _index; }
        set { _index = value; }
    }

    public MyTreeViewItem() : base() 
    {

    }
}

and usage; 
            MyTreeViewItem art = new MyTreeViewItem();
            art.Header = "Node1";
            art.Index = 1; 

            MyTreeViewItem prt = new MyTreeViewItem();
            prt.Header = "Child1";
            prt.Index = 2;

            art.Items.Add(prt);

            treeviewpaneL.Items.Add(art); 

and event; 
  private void treeviewpaneL_SelectedItemChanged(object sender,   RoutedPropertyChangedEventArgs<object> e)
        {
            MyTreeViewItem selectedItem = e.NewValue as MyTreeViewItem;
            if (selectedItem != null) 
            {
                MessageBox.Show("" + selectedItem.Index);

            }
        }

