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

Click_Event in the firsit level

10 Answers 92 Views
Menu
This is a migrated thread and some comments may be shown as answers.
runes
Top achievements
Rank 1
runes asked on 25 Mar 2009, 09:18 AM
Hi,
I have a context menu.
the context menu has two levels : first level and from it exit second level.
I want a click event on the first level .
what I have now is when I click on the first level, the child(second level) opens,
and then when I click on an item on the second level, the event that's assigned to
the first level occurs.

I want a click event on the first level .

The code:

 

 

<StackPanel x:Name="LayoutRoot" Background="White">

 

 

 

<RadioButton Content="Click Me to Open the RadContextMenu">

 

 

 

<telerikNavigation:RadContextMenu.ContextMenu >

 

 

 

<telerikNavigation:RadContextMenu EventName="Click" x:Name="radContextMenu1" ShowDelay="1:0:0">

 

 

 

<telerikNavigation:RadMenuItem Header="Item 1" x:Name="firstLevel">

 

 

 

<telerikNavigation:RadMenuItem Header="Item 2" x:Name="secondLevel" />

 

 

 

</telerikNavigation:RadMenuItem>

 

 

 

 

</telerikNavigation:RadContextMenu>

 

 

 

</telerikNavigation:RadContextMenu.ContextMenu>

 

 

 

</RadioButton>

 

 

 

</StackPanel>

 


public

 

partial class Page : UserControl

 

{

 

public Page()

 

{

InitializeComponent();

firstLevel.Click +=

new RoutedEventHandler(firstLevel_Click);

 

}

 

 

void firstLevel_Click(object sender, RoutedEventArgs e)

 

{

 

}

}
}

Thanks,


10 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 25 Mar 2009, 09:32 AM
Hello runes,

RadMenuItem that have subItems do not fire Click event - only MenuItems that don't have subItems fires it. You can use SubmenuOpened or SubmenuClosed event for menuItems that have subItems.

Let me know if this works for you.

Greetings,
Hristo
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
runes
Top achievements
Rank 1
answered on 25 Mar 2009, 10:35 AM
Thanks,
I have a new question:
How I remove from the context menu child when the child closed?
I try to write in the function : 

SubmenuClosed()

 

 

for (int i = 0; i <count-1 ; i++)

 

{

firstLevel.Items.Remove(0);

}

 

and the items not removed.
How I do it?????

0
Hristo
Telerik team
answered on 25 Mar 2009, 11:38 AM
Hi runes,

This way of removing items is correct.
Just change count-1 to count in the for declaration because you have only 1 item and 0 < 1-1 is false (you won't enter in the for scope).

Let us know if you need more help.

All the best,
Hristo
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
runes
Top achievements
Rank 1
answered on 25 Mar 2009, 12:14 PM
I do it, but the items is not removed from the contect menu  :(  .
I added the items in the function: 

 

SubmenuOpened:

void firstLevel_SubmenuOpened(object sender, RoutedEventArgs e)  
        {  
 
            RadMenuItem tt = new RadMenuItem();  
            tt.Header="eeeeeee";  
            firstLevel.Items.Add(tt);  
            count++;  
 
            RadMenuItem t3 = new RadMenuItem();  
            t3.Header = "wwwww";  
            firstLevel.Items.Add(t3);  
            count++;  
              
        } 

i removed the items in function:

 

SubmenuClosed:

 

 

 void firstLevel_SubmenuClosed(object sender, RoutedEventArgs e)  
        {  
            for (int i = 0; i <count ; i++)  
            {  
                firstLevel.Items.Remove(0);  
            }  
              
        } 

and the items adeed and removed at once.
How I added items in open sub context menu and removed them in closed sub context menu??????
thanks. 

0
Hristo
Telerik team
answered on 26 Mar 2009, 09:55 AM
Hi runes,

Can you elaborate more on your scenario? What you want to achieve?
It is not a common scenario to add MenuItems in SubmenuOpened and remove them SubMenuClosed.

Regards,
Hristo
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Travis
Top achievements
Rank 1
answered on 15 Jul 2010, 07:13 PM
"RadMenuItem that have subItems do not fire Click event "
This is kind of lame.  Seems like standard functionality to me.  The RadMenu for asp.net (web applications) supports this kind of behavior.  We can't use "submenu opened" because the submenu is opened on mouseover.  The user needs to be able to mouseover the menu item to see the submenu and then potentially click on the parent menu. 
0
Travis
Top achievements
Rank 1
answered on 15 Jul 2010, 07:27 PM
"RadMenuItem that have subItems do not fire Click event "
This is kind of lame.  Seems like standard functionality to me.  The RadMenu for asp.net (web applications) supports this kind of behavior.  We can't use "submenu opened" because the submenu is opened on mouseover.  The user needs to be able to mouseover the menu item to see the submenu and then potentially click on the parent menu. 
0
Valeri Hristov
Telerik team
answered on 16 Jul 2010, 01:38 PM
Hello Travis,

The standard WPF menu does not raise Click event for items that have children. This was the case with RadMenu too, but probably an year ago we added the NotifyOnHeaderClick property to RadMenu that allows the cotnrol to raise events when you click on header items (items that have children).

Sincerely yours,
Valeri Hristov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Travis
Top achievements
Rank 1
answered on 19 Jul 2010, 03:16 PM
I was talking about web applications, not WPF.  The r.a.d.menu in web apps has a "NavigateUrl" property which works for top level menu items with children.
0
Valeri Hristov
Telerik team
answered on 19 Jul 2010, 03:29 PM
Hi Travis,

I am talking about RadMenu for Silverlight, which was designed to work exactly as the standard WPF Menu control.
 
The WPF/Silverlight RadMenu does not have NavigateUrl property, it has Command/CommandParameter properties that allow you to execute any code, including navigation to other page. By setting NotifyOnHeaderClick the items that have children will execute their commands, as well as raise their Click events.

Best wishes,
Valeri Hristov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Menu
Asked by
runes
Top achievements
Rank 1
Answers by
Hristo
Telerik team
runes
Top achievements
Rank 1
Travis
Top achievements
Rank 1
Valeri Hristov
Telerik team
Share this question
or