Release click-event when clicking in a menu

10 posts, 1 answers
  1. Kenneth Jensen
    Kenneth Jensen avatar
    4 posts
    Member since:
    May 2010

    Posted 18 Jan 2012 Link to this post

    Hi Telerik
    I have a hierarchical menu like:
    Menu: A
    Submenus: A.1, A.2
    Sub-submenus: A.1.1, A.1.2
    Is it possible to get a click-event when clicking on A or A.1? Normally it only comes when clicking on A.2, A.1.1 or A.1.2.

    It’s really important for one of my controls to have this function so I know at witch level in the hierarchy, that the user makes a choice that releases a click-event and leaves the menu.

    Thanks from Kenneth

  2. Answer
    Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 18 Jan 2012 Link to this post

    Hi Kenneth,

    There is an easy way to achieve this. Just set NotifyOnHeaderClick="True"  and the ItemClick event will be fired even if you click on parent items.

    Hope this helps. Don't hesitate to contact us if you have other questions.

    Kind regards,
    Boyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Kenneth Jensen
    Kenneth Jensen avatar
    4 posts
    Member since:
    May 2010

    Posted 18 Jan 2012 Link to this post

    Works perfect! Thanks Boyan.
  5. Kenneth Jensen
    Kenneth Jensen avatar
    4 posts
    Member since:
    May 2010

    Posted 19 Jan 2012 Link to this post

    Hi again
    I have this menu with:
    Items,
    Sub-items,
    Sub-sub-items,
    Sub-sub-sub-items.

     

    When a user clicks on one of the items, I simply needs to get the Headers content but I can't figure out how to read it.

    I have built an event as follows:

    private void RadMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
           {
               RadMenuItem item = e.Source as RadMenuItem;
               object Header = item.Header;
               //I would like to be able to read the content of the header someway like although this doesn't work:
               string Navn = Header.Where(n => n.Navn).ToString();
           }

    But I don’t know how I can read the content of Header.

    I have attached an image that shows, that I want to be able to read the variable called Navn.

     

    I hope you can help me once again :-)

    With kind regards from Kenneth

  6. Kenneth Jensen
    Kenneth Jensen avatar
    4 posts
    Member since:
    May 2010

    Posted 19 Jan 2012 Link to this post

    I know this for sure isn't pretty but it works.
    Perhaps someone can suggest an easyer way of doing it?
    private void RadMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
           {
               RadMenuItem item = e.Source as RadMenuItem;
               object Header = item.Header;
               string Navn = "";
               if (item.Items.Count > 0)
               {
                   switch (item.Items[1].ToString())
                   {
                       case "bygdrift2.Web.Services.BygdriftServiceClasses.rumNrList_Ejendom":
                           Navn = ((bygdrift2.Web.Services.BygdriftServiceClasses.RumNrList)(Header)).Navn;
                           break;
                       case "bygdrift2.Web.Services.BygdriftServiceClasses.rumNrList_Sal":
                           Navn = ((bygdrift2.Web.Services.BygdriftServiceClasses.rumNrList_Ejendom)(Header)).Navn;
                           break;
                       case "bygdrift2.Web.Services.BygdriftServiceClasses.rumNrList_Lokale":
                            Navn = ((bygdrift2.Web.Services.BygdriftServiceClasses.rumNrList_Sal)(Header)).Navn;
                           break;
                   }
               }
               else
               {
                   Navn = ((bygdrift2.Web.Services.BygdriftServiceClasses.rumNrList_Lokale)(Header)).Navn;
               }
               RadWindow.Alert("Navn is: " + Navn );
           }

    Thanks from Kenneth
  7. Yen-Sheng
    Yen-Sheng avatar
    13 posts
    Member since:
    Aug 2011

    Posted 23 Aug 2012 Link to this post

    My menu item stays open even after being clicked
    I'd rather not have to do any form of "is open" binding.
  8. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 27 Aug 2012 Link to this post

    Hello Yen-Sheng,

    May we receive more information on your case - which version of RadControls are you using, what exactly do you want to happen and the way you are using RadMenu? If you put all this stuff in a sample project it will be a great help for us.

    Looking forward to hearing from you!

    Kind regards,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Yen-Sheng
    Yen-Sheng avatar
    13 posts
    Member since:
    Aug 2011

    Posted 27 Aug 2012 Link to this post

    Telerik version 2012.2.730.1040
    <Grid x:Name="grid">
        <telerik:RadButton>
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu
                    NotifyOnHeaderClick="True">
                    <telerik:RadMenuItem Click="RadMenuItem_Click">
                        <telerik:RadMenuItem.Header>
                            <TextBlock Text="Parent Component"/>
                        </telerik:RadMenuItem.Header>
                        <telerik:RadMenuItem Click="RadMenuItem_Click_1">
                            <telerik:RadMenuItem.Header>
                                <TextBlock Text="Child Component"/>
                            </telerik:RadMenuItem.Header>
                        </telerik:RadMenuItem>
                    </telerik:RadMenuItem>
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
            <TextBlock Text="Button"/>
        </telerik:RadButton>
    Click events can have whatever you want in them.

    Also, are child components suppose to notify the header when clicked?


  10. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 29 Aug 2012 Link to this post

    Hello,

    Please add name to your contextMenu and in the parent Item click event set IsOpen property to false:
    ...
     <telerik:RadContextMenu x:Name="radContextMenu" NotifyOnHeaderClick="True">
    ...

    private void RadMenuItem_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        radContextMenu.IsOpen = false;
    }

    It is expected for the children to notify their parents when they are clicked and then both click events (on the child and on the parent) are raised.

    Hopefully this helps.

    Kind regards,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  11. Yen-Sheng
    Yen-Sheng avatar
    13 posts
    Member since:
    Aug 2011

    Posted 29 Aug 2012 Link to this post

    Somewhat.
    I do realise that being able to click on a parent Item is highly unorthodox.
Back to Top
DevCraft banner