This question is locked. New answers and comments are not allowed.
Has anyone added a context menu to a treeview item dynamically?
I only want to add the context menu if the item is of a certain type. I'm currently working with the ItemPrepared event.
Like this:
How do I add the context menu to the tree view item? I havent found any examples and it isnt exactly obvious (IMO). Thanks!
I only want to add the context menu if the item is of a certain type. I'm currently working with the ItemPrepared event.
Like this:
| private void RuleTree_ItemPrepared(object sender, Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs e) |
| { |
| if (e.PreparedItem.Item is theTypeThatImLookingFor) |
| { |
| // Add an icon. |
| e.PreparedItem.DefaultImageSrc = "../../Resources/Icons/add.png"; |
| // Build menu |
| RadContextMenu menu = new RadContextMenu(); |
| menu.EventName = "MouseLeftButtonDown"; |
| foreach (var name in EnumExtensions.GetNames(typeof (AnEnumeration))) |
| { |
| RadMenuItem menuItem = new RadMenuItem |
| { |
| Header = name.ToString(), |
| }; |
| menuItem.Click += OnContextClick; |
| menu.Items.Add(menuItem); |
| } |
| // TODO: Figure out how to add menu to RadTreeViewItem |
| } |
| } |
How do I add the context menu to the tree view item? I havent found any examples and it isnt exactly obvious (IMO). Thanks!