This project has moved. For the latest updates, please go here.

Bug in BreadcrumbbarNode.BuildDropDownMenu()


Found where things where going wrong. In BuildDropDownMenu there where three bugs.
1) The tsmi ToolStropMenuItem's created from the DropDownMenuItems collection where never added to teh DropDownMenu so it stayed empty
2) There was no safeguard against i.Tag being null (which happened in the original code).
3) At this point things started to show up when clicked, but the delegate code would still crash.
Looking at the code faulting in 2) it also was neccesary to assign item to the tsmi.Tag property instead of using item.Tag 
Which was/is most of the time 0 and cannot be cast into the BreadcrumbDropDownItem expected in the delegate code.
Last remark, from all BreadcrumbBarNode constructors the Tag property can be removed as it's not used at all. Otherwise the delegate code in BuildDropDown menu should also test for the Tag being an object of the BreadcrumbDropDownMenuItem class (added it already in the code below).
Final code:
    private void BuildDropDownMenu()
        foreach (BreadcrumbDropDownItem item in this.DropDownMenuItems)
            ToolStripMenuItem tsmi = new ToolStripMenuItem(item.Text, item.Image,
                delegate(object s, EventArgs e1)
                    ToolStripMenuItem i = s as ToolStripMenuItem;
                    //veg: Added safeguard for Tag being null and of the wrong type
                    if (i.Tag != null && i.Tag is BreadcrumbDropDownItem)
                        BreadcrumbDropDownItem bddi = i.Tag as BreadcrumbDropDownItem;
                        if (bddi.NavigateDelegate != null)
                            bddi.NavigateDelegate.Invoke(bddi, EventArgs.Empty);
                }, item.Text);
            //veg: Changed from item.Tag to item.
            tsmi.Tag = item;
            //veg: Add.