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

5 posts, 1 answers
  1. Rama
    Rama avatar
    8 posts
    Member since:
    Sep 2012

    Posted 02 Jan 2013 Link to this post

    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


  2. Answer
    Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 03 Jan 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Rama
    Rama avatar
    8 posts
    Member since:
    Sep 2012

    Posted 03 Jan 2013 Link to this post

    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
  5. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 03 Jan 2013 Link to this post

    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.

  6. Rama
    Rama avatar
    8 posts
    Member since:
    Sep 2012

    Posted 09 Jan 2013 Link to this post


    It Works.

    Thank you so much for your support.

    Thanks
    Rama
Back to Top
UI for WPF is Visual Studio 2017 Ready