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

Unable to access radmenuitem name in onclick event of the dynamically created RadMenu

4 Answers 110 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Rama
Top achievements
Rank 1
Rama asked on 03 Jan 2013, 01:17 AM

Hi,

I created RadMenu dynamically using HierarchicalDataTemplate using following code.

       <HierarchicalDataTemplate x:Key="MenuItemTemplate"
                                 ItemsSource="{Binding SubItems}">
            <TextBlock Text="{Binding Text}" />
        </HierarchicalDataTemplate>

        <telerik:RadMenu x:Name="radMenu" Height="22"
                          VerticalAlignment="Top"
                          Orientation="Horizontal"
                          ItemTemplate="{StaticResource MenuItemTemplate}" ItemClick="OnRadMenuItemClick" />
but in code behind of the OnRadMenuItemClick Event i am unable to find out name of the menu item that clicked.

		private void OnRadMenuItemClick(object sender, RadRoutedEventArgs e)
		{
			RadMenuItem item = e.OriginalSource as RadMenuItem;
 
			if (item != null)
			{
				switch (item.Name)
				{
		
				}
			}
		}

when i click on menu item .. item.Name allways comming as null.
can one please help me how to get the name of the menu item that clicked

but it is working for statically developed radmenu

Thanks
Rama


4 Answers, 1 is accepted

Sort by
0
Accepted
Rosen Vladimirov
Telerik team
answered on 03 Jan 2013, 08:11 AM
Hi Rama,

You should use item.Header in your switch instead of item.Name. The problem is that if you set the items statically most probably you are setting the x:Name property. When you set the items dynamically this property is not set. I'm sending you a simple project where you will find two RadMenus - one with static and one with dynamic items. You can check the ItemClick logic in code behind.

Hopefully this helps.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rama
Top achievements
Rank 1
answered on 03 Jan 2013, 04:56 PM
Thank you so much for your reply.

The project that you attached does not have files like MainWindow.xaml. Can you verify and send it to me again.

Thank you.
Rama
0
Rosen Vladimirov
Telerik team
answered on 04 Jan 2013, 05:56 AM
Hi Rama,

Please accept my apologize for this mistake. I'm sending you the project again, it should be fine this time.

Don't hesitate to contact us if you have any problems or suggestions.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rama
Top achievements
Rank 1
answered on 10 Jan 2013, 02:02 AM

It Works.

Thank you so much for your support.

Thanks
Rama
Tags
Menu
Asked by
Rama
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Rama
Top achievements
Rank 1
Share this question
or