This is a migrated thread and some comments may be shown as answers.

Handling the submenu click event

2 Answers 78 Views
Menu
This is a migrated thread and some comments may be shown as answers.
paul
Top achievements
Rank 1
paul asked on 09 Sep 2008, 10:34 AM
Hi,

I've replaced my custom menu with the RadMenu. I have several 'headers' such as nodes, carrriers and destinations. Each of the headers has a list of items.

I need to handle the click of the bound itemssource item, and cant see how I can access nodeItems selected child item.... 

The menu items are created as created as follows (main menu and other items excluded for clarity)....

private void CreateMenus()  
{  
    var _nodeNames = new Dictionary<int, string> {{0, "test 1"}, {1, "test 2"}, {2, "test 3"}};  
 
    var mainMenu = new RadMenu();  
 
    var nodesItem = new RadMenuItem { Header = "Nodes"DisplayMemberPath = "Value" };  
    nodesItem.ItemsSource = _nodeNames;  
    nodesItem.Click += nodesItem_Click;  
    mainMenu.Items.Add(nodesItem);  
      
    menuContainer.Children.Add(mainMenu);  
}  
 
private void nodesItem_Click(object sender, RoutedEventArgs e)  
{  
    var selectedItem = sender as RadMenuItem;  
 
    if (selectedItem != null)  
    {  
        //what goes here....  
    }  

Kind Regards,

Paul Chapman
Software Engineer
DIGITALK Limited

2 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 09 Sep 2008, 11:30 AM
Hi Paul,

Generally, you should be able to access the child items through the RadMenuItem Items collection. All the class members are listed in the API here.

In case of databound items though, you can use RoutedEventHandler for RadMenuItem.ClickEvent as in the code snippet below:

        public MyDemo() 
        { 
            InitializeComponent(); 
 
            menu1.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(MenuItemClick)); 
        } 
 
        private void MenuItemClick(object sender, RoutedEventArgs args) 
        { 
            RadMenuItem item = args.OriginalSource as RadMenuItem; 
        } 
 


Regards,
Konstantin Petkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
paul
Top achievements
Rank 1
answered on 09 Sep 2008, 12:53 PM
Sorry, I was having one of those days....I was using the sender not the event args. Thanks for the pointer.

Regards,

Paul Chapman
Software Engineer
DIGITALK Limited
Tags
Menu
Asked by
paul
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
paul
Top achievements
Rank 1
Share this question
or