private ContextMenu InitContextMenu(TreeViewItem item) { var menu = new ContextMenu(); var item1 = new MenuItem(); { menu.Items.Add(item1); item1.Header = "Run"; item1.Click += (o, args) => { StartBackgroundRunner(item); PresentSummary(item); }; } var item2 = new MenuItem(); { menu.Items.Add(item2); item2.Header = "Expand all"; item2.Click += (o, args) => item.ExpandDownRecursive(); } return menu; }