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

Added sub menu dynamicly

5 Answers 147 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, 12:58 PM
Hi,
I want to added sub menu in the context menu in run time . in the event Click (on the father menu).
and i get error .
How i do it?????
Thanks

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 26 Mar 2009, 12:19 PM
Hi runes,

Here is a simple example demonstrating one possible solution to add menu items dynamically on MeunItem Click event.

This is the page.xaml:
<UserControl x:Class="SilverlightApplication30.Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:core="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
    xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.navigation" 
    xmlns:local="clr-namespace:SilverlightApplication30;assembly=SilverlightApplication30">  
    <Grid> 
        <Button Content="Click Me" VerticalAlignment="Center">  
            <nav:RadContextMenu.ContextMenu> 
                <nav:RadContextMenu EventName="Click" x:Name="radContextMenu1">  
                    <nav:RadMenuItem Header="Click me to add more items" /> 
                </nav:RadContextMenu> 
            </nav:RadContextMenu.ContextMenu> 
        </Button> 
    </Grid> 
</UserControl> 

and this is the code-behind:
using System.Windows;  
using System.Windows.Controls;  
using Telerik.Windows;  
using Telerik.Windows.Controls;  
 
namespace SilverlightApplication30  
{  
    public partial class Page : UserControl  
    {  
        public Page()  
        {  
            InitializeComponent();  
            radContextMenu1.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick));  
        }  
 
        private void OnMenuItemClick(object sender, RoutedEventArgs e)  
        {  
            RadRoutedEventArgs args = e as RadRoutedEventArgs;  
            RadMenuItem item = args.OriginalSource as RadMenuItem;  
            RadMenuItem item1 = new RadMenuItem() { Header = "Dynamic 1" };  
            RadMenuItem item2 = new RadMenuItem() { Header = "Dynamic 2" };  
            item.Items.Add(item1);  
            item.Items.Add(item2);  
        }  
    }  

Note that you will need references toTelerik.Windows.Controls and Telerik.Windows.Controls.Navigation assemblies.

Let us know if you need more help.

Sincerely yours,
Hristo
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sai Krishna
Top achievements
Rank 1
answered on 26 Nov 2009, 09:32 AM
Hi,

I am trying to generate context menu item (Parent as well as child menu items) for a RadGrid from server side(C#). but i have no luck.
please provide me solution for this


sai
0
Vlad
Telerik team
answered on 26 Nov 2009, 09:43 AM
Hi,

I'm afraid that you cannot create Silverlight components server-side. You can check however this demo to know more how to generate context menus dynamically on the Silverlight client.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sai Krishna
Top achievements
Rank 1
answered on 26 Nov 2009, 10:44 AM
thanks for the response,

I am not using any silverlight component. it is just normal telerik:RadContextMenu on  telerik:RadGrid.  for ASP.net web application.
0
Vlad
Telerik team
answered on 26 Nov 2009, 11:33 AM
Hello,

This forum is for our Silverlight components - you can post your questions in the relevant forum!

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Menu
Asked by
runes
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Sai Krishna
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or