Added sub menu dynamicly

6 posts, 0 answers
  1. runes
    runes avatar
    15 posts
    Member since:
    Mar 2009

    Posted 25 Mar 2009 Link to this post

    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
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 26 Mar 2009 Link to this post

    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.
  3. DevCraft banner
  4. Sai Krishna
    Sai Krishna avatar
    8 posts
    Member since:
    Nov 2009

    Posted 26 Nov 2009 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Nov 2009 Link to this post

    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.
  6. Sai Krishna
    Sai Krishna avatar
    8 posts
    Member since:
    Nov 2009

    Posted 26 Nov 2009 Link to this post

    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.
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Nov 2009 Link to this post

    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.
Back to Top
DevCraft banner