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

Release click-event when clicking in a menu

9 Answers 110 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kenneth Jensen
Top achievements
Rank 1
Kenneth Jensen asked on 18 Jan 2012, 09:52 AM

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

9 Answers, 1 is accepted

Sort by
0
Accepted
Boyan
Telerik team
answered on 18 Jan 2012, 10:30 AM
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 >>

0
Kenneth Jensen
Top achievements
Rank 1
answered on 18 Jan 2012, 10:48 AM
Works perfect! Thanks Boyan.
0
Kenneth Jensen
Top achievements
Rank 1
answered on 19 Jan 2012, 08:25 AM

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

0
Kenneth Jensen
Top achievements
Rank 1
answered on 19 Jan 2012, 10:53 AM
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
0
Yen-Sheng
Top achievements
Rank 1
answered on 24 Aug 2012, 04:22 AM
My menu item stays open even after being clicked
I'd rather not have to do any form of "is open" binding.
0
Rosen Vladimirov
Telerik team
answered on 27 Aug 2012, 02:53 PM
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.

0
Yen-Sheng
Top achievements
Rank 1
answered on 27 Aug 2012, 08:33 PM
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?


0
Rosen Vladimirov
Telerik team
answered on 29 Aug 2012, 09:52 AM
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.

0
Yen-Sheng
Top achievements
Rank 1
answered on 29 Aug 2012, 08:15 PM
Somewhat.
I do realise that being able to click on a parent Item is highly unorthodox.
Tags
Menu
Asked by
Kenneth Jensen
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Kenneth Jensen
Top achievements
Rank 1
Yen-Sheng
Top achievements
Rank 1
Rosen Vladimirov
Telerik team
Share this question
or