Handling the submenu click event

3 posts, 0 answers
  1. paul
    paul avatar
    16 posts
    Member since:
    Jul 2008

    Posted 09 Sep 2008 Link to this post

    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. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 09 Sep 2008 Link to this post

    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.
  3. DevCraft banner
  4. paul
    paul avatar
    16 posts
    Member since:
    Jul 2008

    Posted 09 Sep 2008 Link to this post

    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
Back to Top