How can I close popup when click a middle level menu item?

5 posts, 0 answers
  1. He
    He avatar
    3 posts
    Member since:
    Oct 2010

    Posted 13 Jul 2011 Link to this post

    Hi, I am using RadMenu to create a three layer menu.
    It is something like :    -TopMenu
                                            -SecondLevel1  -ThirdLevel
                                            -SecondLevel2  

    Now, If I click "ThirdLevel" or "SecondLevel2", the menu will be closed automatically. But If I click "SecondLevel1", nothing happens. I know it is the logic you made it. But I want to close the menu when clicking "SecondLevel1". If there any way to do it?
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 13 Jul 2011 Link to this post

    Hi He Ying,

    The click on the submenu header is used for opening another submenu. When you set a delay for the opening of the popup , the click on the header will still open it immediately despite the delay setting. So you cannot use the click on the header for other implementation purposes like closing the menu.
     
    If you intend to use the desired functionality for marking a user's choice like selection among a variety of options, you might want to consider using checkable menu items. The menu items will be checkable if you set IsCheckable="True".

    I hope this helps.


    Best wishes,
    Dani
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WPF is Visual Studio 2017 Ready
  4. He
    He avatar
    3 posts
    Member since:
    Oct 2010

    Posted 13 Jul 2011 Link to this post

    Hi, Dani

    Thanks for your reply. But I do need "SecondLeve1" works the same as "ThirdLevel" when clicking in the example. The checkable menu item cannot solve my problem. Is there any method that can be used to close the popup in code?

    Best Regards
    He Ying
  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 15 Jul 2011 Link to this post

    Hello,

    RadMenu actually has a property named NotifyOnHeaderClick that was created especially for scenarios like yours. You need to set it to true and the menu will automatically close when you click on items with children. In addition, the ItemClick event will be fired.

    Regards,
    Valeri Hristov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. Dani
    Admin
    Dani avatar
    848 posts

    Posted 15 Jul 2011 Link to this post

    Hi He Ying,

    You can try the following approach:
    private void RadMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
             RadMenuItem item = e.OriginalSource as RadMenuItem;
             while (item.Parent != null)
             {
                      var parent = System.Windows.Controls.ItemsControl.ItemsControlFromItemContainer(item) as RadMenuItem;
                     if (parent != null)
                     {
                              item = parent;
                     }
                     else
                     {
                              break;
                     }
             }
      
             var menuItemAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(item) as RadMenuItemAutomationPeer;
             menuItemAutomationPeer.Collapse();
    }

    I hope this helps.


    Best wishes,
    Dani
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top
UI for WPF is Visual Studio 2017 Ready